1 21 22 package net.percederberg.grammatica; 23 24 31 public class GrammarException extends Exception { 32 33 36 private String file; 37 38 41 private String message; 42 43 46 private int startLine; 47 48 51 private int endLine; 52 53 59 public GrammarException(String file, String message) { 60 this(file, message, -1, -1); 61 } 62 63 71 public GrammarException(String file, 72 String message, 73 int startLine, 74 int endLine) { 75 76 this.file = file; 77 this.message = message; 78 this.startLine = startLine; 79 this.endLine = endLine; 80 } 81 82 87 public String getFile() { 88 return file; 89 } 90 91 97 public int getStartLine() { 98 return startLine; 99 } 100 101 107 public int getEndLine() { 108 return endLine; 109 } 110 111 118 public String getMessage() { 119 StringBuffer buffer = new StringBuffer (); 120 121 buffer.append(getErrorMessage()); 123 124 if (startLine > 0 && endLine > 0) { 126 if (startLine == endLine) { 127 buffer.append(", on line "); 128 buffer.append(startLine); 129 } else { 130 buffer.append(", on lines "); 131 buffer.append(startLine); 132 buffer.append("-"); 133 buffer.append(endLine); 134 } 135 } 136 137 return buffer.toString(); 138 } 139 140 145 public String getErrorMessage() { 146 return message; 147 } 148 } 149 | Popular Tags |