X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSExn.java;h=2afcef188c89e25c0192151c2739d3f34d26628a;hp=8d1a758ee1c6aa503f3e3e7e7f29cc2014fd8a0a;hb=3f8aa5300e178e8975b0edc896a5a9d303e7bdf3;hpb=3591b88b94a6bb378af3d4abe6eb5233ce583104 diff --git a/src/org/ibex/js/JSExn.java b/src/org/ibex/js/JSExn.java index 8d1a758..2afcef1 100644 --- a/src/org/ibex/js/JSExn.java +++ b/src/org/ibex/js/JSExn.java @@ -2,30 +2,51 @@ package org.ibex.js; import org.ibex.util.*; +import java.io.*; /** An exception which can be thrown and caught by JavaScript code */ public class JSExn extends Exception { private Vec backtrace = new Vec(); - private Object js = null; - public JSExn(Object js) { this.js = js; } - public String toString() { return "JSExn: " + js; } + private JS js; + public JSExn(String s) { this(JS.S(s)); } + public JSExn(JS js) { this(js,null); } + public JSExn(JS js, Interpreter cx) { this.js = js; fill(cx); } + + private void fill(Interpreter cx) { + if(cx == null) cx = Interpreter.current(); + if(cx == null) return; + addBacktrace(cx.f.sourceName + ":" + cx.f.line[cx.pc]); + cx.stack.backtrace(this); + } + public void printStackTrace() { printStackTrace(System.err); } + public void printStackTrace(PrintWriter pw) { + for(int i=0; i