Make sure that for Rhino-generated exceptions Throwable.getMessage() contains script file and line information.

This commit is contained in:
igor%mir2.org 2004-05-23 14:32:07 +00:00
Родитель 19184d9a5b
Коммит cfe01facb2
4 изменённых файлов: 33 добавлений и 31 удалений

Просмотреть файл

@ -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);
}
/**

Просмотреть файл

@ -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.
*

Просмотреть файл

@ -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.
*

Просмотреть файл

@ -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() {