in src/main/java/org/apache/bsf/engines/javascript/JavaScriptEngine.java [136:175]
private void handleError(Throwable t) throws BSFException {
if (t instanceof WrappedException) {
t = ((WrappedException) t).getWrappedException();
}
String message = null;
Throwable target = t;
if (t instanceof JavaScriptException) {
message = t.getLocalizedMessage();
// Is it an exception wrapped in a JavaScriptException?
final Object value = ((JavaScriptException) t).getValue();
if (value instanceof Throwable) {
// likely a wrapped exception from a LiveConnect call.
// Display its stack trace as a diagnostic
target = (Throwable) value;
}
} else if (t instanceof EvaluatorException || t instanceof SecurityException) {
message = t.getLocalizedMessage();
} else if (t instanceof RuntimeException) {
message = "Internal Error: " + t.toString();
} else if (t instanceof StackOverflowError) {
message = "Stack Overflow";
}
if (message == null) {
message = t.toString();
}
if (t instanceof Error && !(t instanceof StackOverflowError)) {
// Re-throw Errors because we're supposed to let the JVM see it
// Don't re-throw StackOverflows, because we know we've
// corrected the situation by aborting the loop and
// a long stacktrace would end up on the user's console
throw (Error) t;
} else {
throw new BSFException(BSFException.REASON_OTHER_ERROR, "JavaScript Error: " + message, target);
}
}