From 178f646bc9d0474b32970edb98a9439745f953b7 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Sun, 23 May 2004 14:32:07 +0000 Subject: [PATCH] Make sure that for Rhino-generated exceptions Throwable.getMessage() contains script file and line information. git-svn-id: svn://10.0.0.236/trunk@156802 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/org/mozilla/javascript/Context.java | 10 ++++++- .../javascript/EvaluatorException.java | 27 ++++++++++++++----- .../mozilla/javascript/WrappedException.java | 24 ++--------------- .../javascript/tools/ToolErrorReporter.java | 3 ++- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/Context.java b/mozilla/js/rhino/src/org/mozilla/javascript/Context.java index 7c5aab229f4..af48f7eebb2 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/Context.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/Context.java @@ -1601,7 +1601,15 @@ public class Context if (e instanceof EcmaError) { throw (EcmaError)e; } - throw new WrappedException(e); + String sourceName = null; + int lineNumber = 0; + Context cx = Context.getCurrentContext(); + if (cx != null) { + int[] linep = { 0 }; + sourceName = cx.getSourcePositionFromStack(linep); + lineNumber = linep[0]; + } + throw new WrappedException(e, sourceName, lineNumber); } /** diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/EvaluatorException.java b/mozilla/js/rhino/src/org/mozilla/javascript/EvaluatorException.java index 15aa1182207..567bb1c81d6 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/EvaluatorException.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/EvaluatorException.java @@ -41,14 +41,11 @@ package org.mozilla.javascript; */ public class EvaluatorException extends RuntimeException { - /** - * Create an exception with the specified detail message. - * - * Errors internal to the JavaScript engine will simply throw a - * RuntimeException. - * - * @param detail a message with detail about the exception + * @deprecated Use + * {@link EvaluatorException(String detail, String sourceName, +int lineNumber)} + * to construct detailed error messages. */ public EvaluatorException(String detail) { @@ -61,6 +58,22 @@ public class EvaluatorException extends RuntimeException } } + /** + * Create an exception with the specified detail message. + * + * Errors internal to the JavaScript engine will simply throw a + * RuntimeException. + * + * @param detail the error message + * @param sourceName the name of the source reponsible for the error + * @param lineNumber the line number of the source + */ + public EvaluatorException(String detail, String sourceName, + int lineNumber) + { + this(detail, sourceName, lineNumber, null, 0); + } + /** * Create an exception with the specified detail message. * diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/WrappedException.java b/mozilla/js/rhino/src/org/mozilla/javascript/WrappedException.java index 88618e81e88..e0b201042d2 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/WrappedException.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/WrappedException.java @@ -73,9 +73,9 @@ public class WrappedException extends EvaluatorException * * @param exception the exception to wrap */ - public WrappedException(Throwable exception) + WrappedException(Throwable exception, String sourceName, int lineNumber) { - super(exception.getMessage()); + super("Wrapped "+exception.toString(), sourceName, lineNumber); this.exception = exception; if (initCauseMethod != null) { try { @@ -86,26 +86,6 @@ public class WrappedException extends EvaluatorException } } - /** - * Get the message for the exception. - * - * Delegates to the wrapped exception. - */ - public String getMessage() - { - return "WrappedException of " + exception.toString(); - } - - /** - * Gets the localized message. - * - * Delegates to the wrapped exception. - */ - public String getLocalizedMessage() - { - return "WrappedException of " + exception.getLocalizedMessage(); - } - /** * Get the wrapped exception. * diff --git a/mozilla/js/rhino/toolsrc/org/mozilla/javascript/tools/ToolErrorReporter.java b/mozilla/js/rhino/toolsrc/org/mozilla/javascript/tools/ToolErrorReporter.java index e0fc2d625ef..50feabe4b64 100644 --- a/mozilla/js/rhino/toolsrc/org/mozilla/javascript/tools/ToolErrorReporter.java +++ b/mozilla/js/rhino/toolsrc/org/mozilla/javascript/tools/ToolErrorReporter.java @@ -132,7 +132,8 @@ public class ToolErrorReporter implements ErrorReporter { int lineOffset) { error(message, sourceName, line, lineSource, lineOffset); - return new EvaluatorException(message); + return new EvaluatorException(message, sourceName, line, + lineSource, lineOffset); } public boolean hasReportedError() {