df1022efd12d574ff7356d635887a4e66d659124
[org.ibex.core.git] / src / org / xwt / js / JSExn.java
1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] 
2 package org.xwt.js; 
3
4 import org.xwt.util.*; 
5 import org.xwt.*; 
6 import java.io.*;
7 import java.util.*;
8
9 /** An exception which can be thrown and caught by JavaScript code */
10 public class JSExn extends Exception { 
11     private Vec backtrace = new Vec();
12     private Object js = null; 
13     public JSExn(Object js) { this.js = js; } 
14     public String toString() { return "JSExn: " + js; }
15     public String getMessage() { return toString(); }
16     public Object getObject() { return js; } 
17     public void addBacktrace(String sourceName, int lineNo) { backtrace.addElement(sourceName + ":" + lineNo); }
18     public String backtrace() {
19         StringBuffer sb = new StringBuffer(1024);
20         for(int i=0;i<backtrace.size();i++)
21             sb.append("    at " + (String) backtrace.elementAt(i) + "\n");
22         return sb.toString();
23     }
24
25
26 /** should only be used for failed coercions */
27 class JSRuntimeExn extends RuntimeException {
28     private Object js = null; 
29     public JSRuntimeExn(Object js) { this.js = js; } 
30     public String toString() { return "JSRuntimeExn: " + js; }
31     public String getMessage() { return toString(); }
32     public Object getObject() { return js; } 
33 }
34