01: package org.drools.lang;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.drools.RuntimeDroolsException;
20:
21: public class ParseException extends RuntimeDroolsException {
22:
23: private static final long serialVersionUID = 400L;
24:
25: private int lineNumber;
26:
27: private Throwable cause;
28:
29: /**
30: * Thrown if there is an exception related to parsing a line in a drl file.
31: * For more generic exception, a different exception class will be used.
32: */
33: public ParseException(final String message, final int lineNumber) {
34: super (message);
35: this .lineNumber = lineNumber;
36: }
37:
38: /**
39: * Allows nesting of misc exceptions, yet preserving the line number
40: * that triggered the error.
41: */
42: public ParseException(final String message, final int lineNumber,
43: final Throwable cause) {
44: super (message);
45: this .lineNumber = lineNumber;
46: this .cause = cause;
47: }
48:
49: /**
50: * The line number on which the error occurred.
51: */
52: public int getLineNumber() {
53: return this .lineNumber;
54: }
55:
56: /**
57: * This will print out a summary, including the line number.
58: * It will also print out the cause message if applicable.
59: */
60: public String getMessage() {
61: if (this .cause == null) {
62: return super .getMessage() + " Line number: "
63: + this .lineNumber;
64: } else {
65: return super .getMessage() + " Line number: "
66: + this .lineNumber + ". Caused by: "
67: + this .cause.getMessage();
68: }
69: }
70:
71: public String toString() {
72: return getMessage();
73: }
74:
75: public Throwable getCause() {
76: return this.cause;
77: }
78:
79: }
|