--- /dev/null
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-\r
+ *\r
+ * The contents of this file are subject to the Netscape Public\r
+ * License Version 1.1 (the "License"); you may not use this file\r
+ * except in compliance with the License. You may obtain a copy of\r
+ * the License at http://www.mozilla.org/NPL/\r
+ *\r
+ * Software distributed under the License is distributed on an "AS\r
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr\r
+ * implied. See the License for the specific language governing\r
+ * rights and limitations under the License.\r
+ *\r
+ * The Original Code is Rhino code, released\r
+ * May 6, 1999.\r
+ *\r
+ * The Initial Developer of the Original Code is Netscape\r
+ * Communications Corporation. Portions created by Netscape are\r
+ * Copyright (C) 1997-1999 Netscape Communications Corporation. All\r
+ * Rights Reserved.\r
+ *\r
+ * Contributor(s): \r
+ * Roger Lawrence\r
+ * \r
+ * Alternatively, the contents of this file may be used under the\r
+ * terms of the GNU Public License (the "GPL"), in which case the\r
+ * provisions of the GPL are applicable instead of those above.\r
+ * If you wish to allow use of your version of this file only\r
+ * under the terms of the GPL and not to allow others to use your\r
+ * version of this file under the NPL, indicate your decision by\r
+ * deleting the provisions above and replace them with the notice\r
+ * and other provisions required by the GPL. If you do not delete\r
+ * the provisions above, a recipient may use your version of this\r
+ * file under either the NPL or the GPL.\r
+ */\r
+\r
+// API class\r
+\r
+package org.mozilla.javascript;\r
+\r
+/**\r
+ * The class of exceptions raised by the engine as described in \r
+ * ECMA edition 3. See section 15.11.6 in particular.\r
+ */\r
+public class EcmaError extends RuntimeException {\r
+\r
+ /**\r
+ * Create an exception with the specified detail message.\r
+ *\r
+ * Errors internal to the JavaScript engine will simply throw a\r
+ * RuntimeException.\r
+ *\r
+ * @param nativeError the NativeError object constructed for this error\r
+ * @param sourceName the name of the source reponsible for the error\r
+ * @param lineNumber the line number of the source\r
+ * @param columnNumber the columnNumber of the source (may be zero if\r
+ * unknown)\r
+ * @param lineSource the source of the line containing the error (may be \r
+ * null if unknown)\r
+ */\r
+ public EcmaError(NativeError nativeError, String sourceName, \r
+ int lineNumber, int columnNumber, String lineSource) \r
+ {\r
+ super("EcmaError");\r
+ errorObject = nativeError;\r
+ this.sourceName = sourceName;\r
+ this.lineNumber = lineNumber;\r
+ this.columnNumber = columnNumber;\r
+ this.lineSource = lineSource;\r
+ }\r
+ \r
+ /**\r
+ * Return a string representation of the error, which currently consists \r
+ * of the name of the error together with the message.\r
+ */\r
+ public String toString() {\r
+ if (sourceName != null && lineNumber > 0)\r
+ return errorObject.toString() + " (" + sourceName + \r
+ "; line " + lineNumber + ")";\r
+ else\r
+ return errorObject.toString();\r
+ }\r
+ \r
+ /**\r
+ * Gets the name of the error.\r
+ * \r
+ * ECMA edition 3 defines the following\r
+ * errors: EvalError, RangeError, ReferenceError, \r
+ * SyntaxError, TypeError, and URIError. Additional error names\r
+ * may be added in the future.\r
+ * \r
+ * See ECMA edition 3, 15.11.7.9.\r
+ * \r
+ * @return the name of the error. \r
+ */\r
+ public String getName() {\r
+ return errorObject.getName();\r
+ }\r
+ \r
+ /**\r
+ * Gets the message corresponding to the error.\r
+ * \r
+ * See ECMA edition 3, 15.11.7.10.\r
+ * \r
+ * @return an implemenation-defined string describing the error.\r
+ */\r
+ public String getMessage() {\r
+ return errorObject.getMessage();\r
+ }\r
+ \r
+ /**\r
+ * Get the name of the source containing the error, or null\r
+ * if that information is not available.\r
+ */\r
+ public String getSourceName() {\r
+ return sourceName;\r
+ }\r
+ \r
+ /**\r
+ * Returns the line number of the statement causing the error,\r
+ * or zero if not available.\r
+ */\r
+ public int getLineNumber() {\r
+ return lineNumber;\r
+ }\r
+ \r
+ /**\r
+ * Get the error object corresponding to this exception.\r
+ */\r
+ public Scriptable getErrorObject() {\r
+ return errorObject;\r
+ }\r
+ \r
+ /**\r
+ * The column number of the location of the error, or zero if unknown.\r
+ */\r
+ public int getColumnNumber() {\r
+ return columnNumber;\r
+ }\r
+ \r
+ /**\r
+ * The source of the line causing the error, or zero if unknown.\r
+ */\r
+ public String getLineSource() {\r
+ return lineSource;\r
+ }\r
+ \r
+ private NativeError errorObject;\r
+ private String sourceName;\r
+ private int lineNumber;\r
+ private int columnNumber;\r
+ private String lineSource;\r
+}\r