01: /*
02: * Copyright 2004,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.bsf;
18:
19: /**
20: * If something goes wrong while doing some scripting stuff, one of these
21: * is thrown. The integer code indicates what's wrong and the message
22: * may give more details. The reason one exception with multiple meanings
23: * (via the code) [instead of multiple exception types] is used is due to
24: * the interest to keep the run-time size small.
25: *
26: * @author Sanjiva Weerawarana
27: */
28: public class BSFException extends Exception {
29: public static final int REASON_INVALID_ARGUMENT = 0;
30: public static final int REASON_IO_ERROR = 10;
31: public static final int REASON_UNKNOWN_LANGUAGE = 20;
32: public static final int REASON_EXECUTION_ERROR = 100;
33: public static final int REASON_UNSUPPORTED_FEATURE = 499;
34: public static final int REASON_OTHER_ERROR = 500;
35:
36: int reason;
37: Throwable targetThrowable;
38:
39: public BSFException(int reason, String msg) {
40: super (msg);
41: this .reason = reason;
42: }
43:
44: public BSFException(int reason, String msg, Throwable t) {
45: this (reason, msg);
46: targetThrowable = t;
47: }
48:
49: public BSFException(String msg) {
50: this (REASON_OTHER_ERROR, msg);
51: }
52:
53: public int getReason() {
54: return reason;
55: }
56:
57: public Throwable getTargetException() {
58: return targetThrowable;
59: }
60:
61: public void printStackTrace() {
62: if (targetThrowable != null) {
63: String msg = getMessage();
64:
65: if (msg != null
66: && !msg.equals(targetThrowable.getMessage())) {
67: System.err.print(msg + ": ");
68: }
69:
70: targetThrowable.printStackTrace();
71: } else {
72: super.printStackTrace();
73: }
74: }
75: }
|