01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. 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: package org.apache.batik.script;
20:
21: /**
22: * An exception that will be thrown when a problem is encountered in the
23: * script by an <code>Interpreter</code> interface implementation.
24: *
25: * @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
26: * @version $Id: InterpreterException.java 475477 2006-11-15 22:44:28Z cam $
27: */
28: public class InterpreterException extends RuntimeException {
29: private int line = -1; // -1 when unknown
30: private int column = -1; // -1 when unknown
31: private Exception embedded = null; // null when unknown
32:
33: /**
34: * Builds an instance of <code>InterpreterException</code>.
35: * @param message the <code>Exception</code> message.
36: * @param lineno the number of the line the error occurs.
37: * @param columnno the number of the column the error occurs.
38: */
39: public InterpreterException(String message, int lineno, int columnno) {
40: super (message);
41: line = lineno;
42: column = columnno;
43: }
44:
45: /**
46: * Builds an instance of <code>InterpreterException</code>.
47: * @param exception the embedded exception.
48: * @param message the <code>Exception</code> message.
49: * @param lineno the number of the line the error occurs.
50: * @param columnno the number of the column the error occurs.
51: */
52: public InterpreterException(Exception exception, String message,
53: int lineno, int columnno) {
54: this (message, lineno, columnno);
55: embedded = exception;
56: }
57:
58: /**
59: * Returns the line number where the error occurs. If this value is not
60: * known, returns -1.
61: */
62: public int getLineNumber() {
63: return line;
64: }
65:
66: /**
67: * Returns the column number where the error occurs. If this value is not
68: * known, returns -1.
69: */
70: public int getColumnNumber() {
71: return column;
72: }
73:
74: /**
75: * Returns the embedded exception. If no embedded exception is set,
76: * returns null.
77: */
78: public Exception getException() {
79: return embedded;
80: }
81:
82: /**
83: * Returns the message of this exception. If an error message has
84: * been specified, returns that one. Otherwise, return the error message
85: * of enclosed exception or null if any.
86: */
87: public String getMessage() {
88: String msg = super.getMessage();
89: if (msg != null) {
90: return msg;
91: } else if (embedded != null) {
92: return embedded.getMessage();
93: } else {
94: return null;
95: }
96: }
97: }
|