1
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is Rhino code, released
16
* The Initial Developer of the Original Code is Netscape
17
* Communications Corporation. Portions created by Netscape are
18
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
24
* Alternatively, the contents of this file may be used under the
25
* terms of the GNU Public License (the "GPL"), in which case the
26
* provisions of the GPL are applicable instead of those above.
27
* If you wish to allow use of your version of this file only
28
* under the terms of the GPL and not to allow others to use your
29
* version of this file under the NPL, indicate your decision by
30
* deleting the provisions above and replace them with the notice
31
* and other provisions required by the GPL. If you do not delete
32
* the provisions above, a recipient may use your version of this
33
* file under either the NPL or the GPL.
38
package org.mozilla.javascript;
41
* The class of exceptions raised by the engine as described in
42
* ECMA edition 3. See section 15.11.6 in particular.
44
public class EcmaError extends RuntimeException {
47
* Create an exception with the specified detail message.
49
* Errors internal to the JavaScript engine will simply throw a
52
* @param nativeError the NativeError object constructed for this error
53
* @param sourceName the name of the source reponsible for the error
54
* @param lineNumber the line number of the source
55
* @param columnNumber the columnNumber of the source (may be zero if
57
* @param lineSource the source of the line containing the error (may be
60
public EcmaError(NativeError nativeError, String sourceName,
61
int lineNumber, int columnNumber, String lineSource)
64
errorObject = nativeError;
65
this.sourceName = sourceName;
66
this.lineNumber = lineNumber;
67
this.columnNumber = columnNumber;
68
this.lineSource = lineSource;
72
* Return a string representation of the error, which currently consists
73
* of the name of the error together with the message.
75
public String toString() {
76
if (sourceName != null && lineNumber > 0)
77
return errorObject.toString() + " (" + sourceName +
78
"; line " + lineNumber + ")";
80
return errorObject.toString();
84
* Gets the name of the error.
86
* ECMA edition 3 defines the following
87
* errors: EvalError, RangeError, ReferenceError,
88
* SyntaxError, TypeError, and URIError. Additional error names
89
* may be added in the future.
91
* See ECMA edition 3, 15.11.7.9.
93
* @return the name of the error.
95
public String getName() {
96
return errorObject.getName();
100
* Gets the message corresponding to the error.
102
* See ECMA edition 3, 15.11.7.10.
104
* @return an implemenation-defined string describing the error.
106
public String getMessage() {
107
return errorObject.getMessage();
111
* Get the name of the source containing the error, or null
112
* if that information is not available.
114
public String getSourceName() {
119
* Returns the line number of the statement causing the error,
120
* or zero if not available.
122
public int getLineNumber() {
127
* Get the error object corresponding to this exception.
129
public Scriptable getErrorObject() {
134
* The column number of the location of the error, or zero if unknown.
136
public int getColumnNumber() {
141
* The source of the line causing the error, or zero if unknown.
143
public String getLineSource() {
147
private NativeError errorObject;
148
private String sourceName;
149
private int lineNumber;
150
private int columnNumber;
151
private String lineSource;
1
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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/
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.
13
* The Original Code is Rhino code, released
16
* The Initial Developer of the Original Code is Netscape
17
* Communications Corporation. Portions created by Netscape are
18
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
24
* Alternatively, the contents of this file may be used under the
25
* terms of the GNU Public License (the "GPL"), in which case the
26
* provisions of the GPL are applicable instead of those above.
27
* If you wish to allow use of your version of this file only
28
* under the terms of the GPL and not to allow others to use your
29
* version of this file under the NPL, indicate your decision by
30
* deleting the provisions above and replace them with the notice
31
* and other provisions required by the GPL. If you do not delete
32
* the provisions above, a recipient may use your version of this
33
* file under either the NPL or the GPL.
38
package org.mozilla.javascript;
41
* The class of exceptions raised by the engine as described in
42
* ECMA edition 3. See section 15.11.6 in particular.
44
public class EcmaError extends RhinoException
47
* Create an exception with the specified detail message.
49
* Errors internal to the JavaScript engine will simply throw a
52
* @param sourceName the name of the source reponsible for the error
53
* @param lineNumber the line number of the source
54
* @param columnNumber the columnNumber of the source (may be zero if
56
* @param lineSource the source of the line containing the error (may be
59
EcmaError(String errorName, String errorMessage,
60
String sourceName, int lineNumber,
61
String lineSource, int columnNumber)
63
recordErrorOrigin(sourceName, lineNumber, lineSource, columnNumber);
64
this.errorName = errorName;
65
this.errorMessage = errorMessage;
69
* @deprecated EcmaError error instances should not be constructed
70
* explicitly since they are generated by the engine.
72
public EcmaError(Scriptable nativeError, String sourceName,
73
int lineNumber, int columnNumber, String lineSource)
75
this("InternalError", ScriptRuntime.toString(nativeError),
76
sourceName, lineNumber, lineSource, columnNumber);
79
public String details()
81
return errorName+": "+errorMessage;
85
* Gets the name of the error.
87
* ECMA edition 3 defines the following
88
* errors: EvalError, RangeError, ReferenceError,
89
* SyntaxError, TypeError, and URIError. Additional error names
90
* may be added in the future.
92
* See ECMA edition 3, 15.11.7.9.
94
* @return the name of the error.
96
public String getName() {
101
* Gets the message corresponding to the error.
103
* See ECMA edition 3, 15.11.7.10.
105
* @return an implemenation-defined string describing the error.
107
public String getErrorMessage() {
112
* @deprecated Use {@link RhinoException#sourceName()} from the super class.
114
public String getSourceName() {
119
* @deprecated Use {@link RhinoException#lineNumber()} from the super class.
121
public int getLineNumber() {
126
* @deprecated Use {@link RhinoException#columnNumber()} from the super class.
128
public int getColumnNumber() {
129
return columnNumber();
133
* @deprecated Use {@link RhinoException#lineSource()} from the super class.
135
public String getLineSource() {
140
* @deprecated Always returns result of {@link Context#getUndefinedValue()}.
143
public Scriptable getErrorObject()
145
return Undefined.instance;
148
private String errorName;
149
private String errorMessage;