From ca657b86aedd7c0e8b517195b4d7766121ca25d5 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Thu, 11 Sep 2003 15:41:06 +0000 Subject: [PATCH] Siplified code to extract error message from Throwable to reflect recent changes in exception-related API semantics. --- .../javascript/tools/debugger/Main.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java b/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java index 049ff41d186f..08ab750ebab7 100644 --- a/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java +++ b/js/rhino/toolsrc/org/mozilla/javascript/tools/debugger/Main.java @@ -2624,23 +2624,23 @@ public class Main extends JFrame implements Debugger, ContextListener { interrupted(cx); } - private static Object unwrapException(Object ex) { - for (;;) { - if (ex instanceof JavaScriptException) { - ex = ((JavaScriptException)ex).getValue(); - } else if (ex instanceof EcmaError) { - ex = ((EcmaError)ex).getErrorObject(); - } else if (ex instanceof NativeJavaObject) { - ex = ((NativeJavaObject)ex).unwrap(); - break; - } else if (ex instanceof WrappedException) { - ex = ((WrappedException)ex).getWrappedException(); - continue; - } else { - break; + private static String exceptionString(Throwable ex) { + if (ex instanceof JavaScriptException) { + JavaScriptException jse = (JavaScriptException)ex; + return ScriptRuntime.toString(jse.getValue()); + } else if (ex instanceof EcmaError) { + return ex.toString(); + } else if (ex instanceof WrappedException) { + Throwable wrapped = ((WrappedException)ex).getWrappedException(); + if (wrapped != null) { + ex = wrapped; } } - return ex; + String msg = ex.toString(); + if (msg == null || msg.length() == 0) { + msg = ex.getClass().toString(); + } + return msg; } void handleExceptionThrown(Context cx, Throwable ex, FrameHelper frame) { @@ -2648,11 +2648,7 @@ public class Main extends JFrame implements Debugger, ContextListener { String url = frame.getUrl(); int lineNumber = frame.getLineNumber(); FileWindow w = getFileWindow(url); - Object e = unwrapException(ex); - String msg = e.toString(); - if (msg == null || msg.length() == 0) { - msg = e.getClass().toString(); - } + String msg = exceptionString(ex); msg += " (" + url + ", line " + lineNumber + ")"; if (w != null) { swingInvoke(new SetFilePosition(this, w, lineNumber));