1 21 22 package nu.xom; 23 24 41 public class ParsingException extends Exception { 42 43 44 private Throwable cause; 45 private int lineNumber = -1; 46 private int columnNumber = -1; 47 private String uri; 48 49 50 59 public ParsingException(String message, Throwable cause) { 60 super(message); 61 this.initCause(cause); 62 } 63 64 65 75 public ParsingException(String message, String uri, Throwable cause) { 76 super(message); 77 this.uri = uri; 78 this.initCause(cause); 79 } 80 81 82 94 public ParsingException(String message, 95 int lineNumber, int columnNumber) { 96 this(message, null, lineNumber, columnNumber, null); 97 } 98 99 100 113 public ParsingException(String message, String uri, 114 int lineNumber, int columnNumber) { 115 this(message, uri, lineNumber, columnNumber, null); 116 } 117 118 119 133 public ParsingException(String message, String uri, int lineNumber, 134 int columnNumber, Throwable cause) { 135 super(message); 136 this.lineNumber = lineNumber; 137 this.columnNumber = columnNumber; 138 this.uri = uri; 139 this.initCause(cause); 140 } 141 142 143 156 public ParsingException(String message, int lineNumber, 157 int columnNumber, Throwable cause) { 158 super(message); 159 this.lineNumber = lineNumber; 160 this.columnNumber = columnNumber; 161 this.initCause(cause); 162 } 163 164 165 172 public ParsingException(String message) { 173 super(message); 174 } 175 176 177 186 public int getLineNumber() { 187 return this.lineNumber; 188 } 189 190 199 public int getColumnNumber() { 200 return this.columnNumber; 201 } 202 203 204 214 public String getURI() { 215 return this.uri; 216 } 217 218 219 private boolean causeSet = false; 222 223 244 public Throwable initCause(Throwable cause) { 245 246 if (causeSet) { 247 throw new IllegalStateException ("Can't overwrite cause"); 248 } 249 else if (cause == this) { 250 throw new IllegalArgumentException ("Self-causation not permitted"); 251 } 252 else this.cause = cause; 253 causeSet = true; 254 return this; 255 256 } 257 258 259 267 public Throwable getCause() { 268 return this.cause; 269 } 270 271 272 280 public String toString() { 281 return super.toString() + " at line " 282 + lineNumber + ", column " + columnNumber + "."; 283 } 284 285 286 } | Popular Tags |