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