mass rename and rebranding from xwt to ibex - fixed to use ixt files
[org.ibex.core.git] / src / org / ibex / js / JSExn.java
diff --git a/src/org/ibex/js/JSExn.java b/src/org/ibex/js/JSExn.java
new file mode 100644 (file)
index 0000000..8d1a758
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] 
+package org.ibex.js; 
+
+import org.ibex.util.*; 
+
+/** 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; }
+    public String getMessage() { return toString(); }
+    public Object getObject() { return js; } 
+    public void addBacktrace(String sourceName, int lineNo) { backtrace.addElement(sourceName + ":" + lineNo); }
+    public String backtrace() {
+        StringBuffer sb = new StringBuffer(1024);
+        for(int i=0;i<backtrace.size();i++)
+            sb.append("    at " + (String) backtrace.elementAt(i) + "\n");
+        return sb.toString();
+    }
+} 
+
+/** should only be used for failed coercions */
+class JSRuntimeExn extends RuntimeException {
+    private Object js = null; 
+    public JSRuntimeExn(Object js) { this.js = js; } 
+    public String toString() { return "JSRuntimeExn: " + js; }
+    public String getMessage() { return toString(); }
+    public Object getObject() { return js; } 
+}
+