Source code: netscape/javascript/JSException.java
1 /* -*- Mode: Java; tab-width: 8; c-basic-offset: 4 -*-
2 *
3 * The contents of this file are subject to the Netscape Public
4 * License Version 1.1 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of
6 * the License at http://www.mozilla.org/NPL/
7 *
8 * Software distributed under the License is distributed on an "AS
9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the License for the specific language governing
11 * rights and limitations under the License.
12 *
13 * The Original Code is Mozilla Communicator client code, released
14 * March 31, 1998.
15 *
16 * The Initial Developer of the Original Code is Netscape
17 * Communications Corporation. Portions created by Netscape are
18 * Copyright (C) 1998 Netscape Communications Corporation. All
19 * Rights Reserved.
20 *
21 * Contributor(s):
22 *
23 * Alternatively, the contents of this file may be used under the
24 * terms of the GNU Public License (the "GPL"), in which case the
25 * provisions of the GPL are applicable instead of those above.
26 * If you wish to allow use of your version of this file only
27 * under the terms of the GPL and not to allow others to use your
28 * version of this file under the NPL, indicate your decision by
29 * deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL. If you do not delete
31 * the provisions above, a recipient may use your version of this
32 * file under either the NPL or the GPL.
33 */
34
35 package netscape.javascript;
36
37 /**
38 * JSException is an exception which is thrown when JavaScript code
39 * returns an error.
40 */
41
42 public
43 class JSException extends RuntimeException {
44 public static final int EXCEPTION_TYPE_EMPTY = -1;
45 public static final int EXCEPTION_TYPE_VOID = 0;
46 public static final int EXCEPTION_TYPE_OBJECT = 1;
47 public static final int EXCEPTION_TYPE_FUNCTION = 2;
48 public static final int EXCEPTION_TYPE_STRING = 3;
49 public static final int EXCEPTION_TYPE_NUMBER = 4;
50 public static final int EXCEPTION_TYPE_BOOLEAN = 5;
51 public static final int EXCEPTION_TYPE_ERROR = 6;
52
53 String filename;
54 int lineno;
55 String source;
56 int tokenIndex;
57 private int wrappedExceptionType;
58 private Object wrappedException;
59
60 /**
61 * Constructs a JSException without a detail message.
62 * A detail message is a String that describes this particular exception.
63 *
64 * @deprecated Not for public use in future versions.
65 */
66 public JSException() {
67 super();
68 filename = "unknown";
69 lineno = 0;
70 source = "";
71 tokenIndex = 0;
72 wrappedExceptionType = EXCEPTION_TYPE_EMPTY;
73 }
74
75 /**
76 * Constructs a JSException with a detail message.
77 * A detail message is a String that describes this particular exception.
78 * @param s the detail message
79 *
80 * @deprecated Not for public use in future versions.
81 */
82 public JSException(String s) {
83 super(s);
84 filename = "unknown";
85 lineno = 0;
86 source = "";
87 tokenIndex = 0;
88 wrappedExceptionType = EXCEPTION_TYPE_EMPTY;
89 }
90
91 /**
92 * Constructs a JSException with a wrapped JavaScript exception object.
93 * This constructor needs to be public so that Java users can throw
94 * exceptions to JS cleanly.
95 */
96 private JSException(int wrappedExceptionType, Object wrappedException) {
97 super();
98 this.wrappedExceptionType = wrappedExceptionType;
99 this.wrappedException = wrappedException;
100 }
101
102 /**
103 * Constructs a JSException with a detail message and all the
104 * other info that usually comes with a JavaScript error.
105 * @param s the detail message
106 *
107 * @deprecated Not for public use in future versions.
108 */
109 public JSException(String s, String filename, int lineno,
110 String source, int tokenIndex) {
111 super(s);
112 this.filename = filename;
113 this.lineno = lineno;
114 this.source = source;
115 this.tokenIndex = tokenIndex;
116 wrappedExceptionType = EXCEPTION_TYPE_EMPTY;
117 }
118
119 /**
120 * Instance method getWrappedExceptionType returns the int mapping of the
121 * type of the wrappedException Object.
122 */
123 public int getWrappedExceptionType() {
124 return wrappedExceptionType;
125 }
126
127 /**
128 * Instance method getWrappedException.
129 */
130 public Object getWrappedException() {
131 return wrappedException;
132 }
133
134 }
135