Revision: 1750
          http://svn.sourceforge.net/vexi/?rev=1750&view=rev
Author:   mkpg2
Date:     2007-03-26 07:31:27 -0700 (Mon, 26 Mar 2007)

Log Message:
-----------
Feature. Handle unexpected core exceptions more gracefully

Modified Paths:
--------------
    core/trunk/org.ibex.js/src/org/ibex/js/Interpreter.jpp
    core/trunk/org.ibex.js/src/org/ibex/js/JS.jpp
    core/trunk/org.ibex.js/src/org/ibex/js/JSExn.java
    
core/trunk/org.ibex.js/src_junit/test/js/traps_pause_on_put/TestPauseOnPut.java
    core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp

Added Paths:
-----------
    core/trunk/org.ibex.js/src_junit/test/js/exceptions/java/
    core/trunk/org.ibex.js/src_junit/test/js/exceptions/java/TestExceptions.java
    core/trunk/org.ibex.js/src_junit/test/js/exceptions/java/handled.js

Modified: core/trunk/org.ibex.js/src/org/ibex/js/Interpreter.jpp
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/Interpreter.jpp      2007-03-25 
07:22:28 UTC (rev 1749)
+++ core/trunk/org.ibex.js/src/org/ibex/js/Interpreter.jpp      2007-03-26 
14:31:27 UTC (rev 1750)
@@ -537,8 +537,9 @@
                 } }
             }
 
-        } catch(JSExn e) {
-            catchException(e);
+        } catch(Exception e) {
+               if(!(e instanceof JSExn)){e = new JSExn(e);}
+            catchException((JSExn)e);
             pc--; // it'll get incremented on the next iteration
         } // end try/catch
         } // end for

Modified: core/trunk/org.ibex.js/src/org/ibex/js/JS.jpp
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/JS.jpp       2007-03-25 07:22:28 UTC 
(rev 1749)
+++ core/trunk/org.ibex.js/src/org/ibex/js/JS.jpp       2007-03-26 14:31:27 UTC 
(rev 1750)
@@ -132,13 +132,18 @@
                        Thread.runBeforePut(t, val);
                                
if(Thread.lastReturn!=Interpreter.CASCADE_PREVENTED)
                                        put(key, Thread.lastReturn);
-               }catch(Exception e){
+               }catch(JSExn e){
                        wasException = true;
+                       throw e;
+               }
+               /* REMARK can only have JSExns ... TODO remove later
+               catch(Exception e){
+                       wasException = true;
                        if(e instanceof JSExn)
                                throw (JSExn)e;
                        else 
                                throw new JSExn(e.getMessage());
-               }finally{
+               }*/finally{
                        Thread.runAfterPut(wasException);
                }
             }else{
@@ -250,13 +255,19 @@
                        Thread.runBeforePut(t, val);
                                
if(Thread.lastReturn!=Interpreter.CASCADE_PREVENTED)
                                        put(key, Thread.lastReturn);
-               }catch(Exception e){
+               }catch(JSExn e){
                        wasException = true;
+                       throw e;
+               }
+               /* REMARK can only have JSExns ... TODO remove later
+               catch(Exception e){
+                       wasException = true;
                        if(e instanceof JSExn)
                                throw (JSExn)e;
                        else 
                                throw new JSExn(e.getMessage());
-               }finally{
+               }*/
+               finally{
                        Thread.runAfterPut(wasException);
                }
             }else{

Modified: core/trunk/org.ibex.js/src/org/ibex/js/JSExn.java
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/JSExn.java   2007-03-25 07:22:28 UTC 
(rev 1749)
+++ core/trunk/org.ibex.js/src/org/ibex/js/JSExn.java   2007-03-26 14:31:27 UTC 
(rev 1750)
@@ -16,7 +16,11 @@
     public static final int MAX_BACKTRACE_SIZE = 20;
 
     private Basket.List backtrace = new Basket.Array();
-    private ExnJSObj js = null; 
+    private ExnJSObj js = null;
+    public JSExn(Exception e) { 
+       this("Unexpected Java exception thrown by the core\n" + 
e.getClass().getName() + ":" + e.getMessage()); 
+       Log.warn(JSExn.class, e);
+    }
     public JSExn(String s) { this(JSU.S(s)); }
     public JSExn(JS msg) { this(msg,null); }
     public JSExn(JS msg, JS type) { this(msg,type,null); }

Added: 
core/trunk/org.ibex.js/src_junit/test/js/exceptions/java/TestExceptions.java
===================================================================
--- 
core/trunk/org.ibex.js/src_junit/test/js/exceptions/java/TestExceptions.java    
                            (rev 0)
+++ 
core/trunk/org.ibex.js/src_junit/test/js/exceptions/java/TestExceptions.java    
    2007-03-26 14:31:27 UTC (rev 1750)
@@ -0,0 +1,75 @@
+package test.js.exceptions.java;
+
+import org.ibex.js.JSExn;
+import org.ibex.js.JSU;
+import org.ibex.js.RunJS;
+import org.ibex.js.JS;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import test.js.JSTestCase;
+import test.js.JSTestSuite;
+import test.js.rpc.xmlrpc.TestXmlRpc;
+
+/**
+ * @author mike
+ */
+public class TestExceptions extends JSTestSuite{
+
+
+    public static Test suite() {
+       return JSTestSuite.suite(new TestExceptions());
+    }
+    
+    public static void main(String[] args) throws Exception {
+       String resourceDir = TestExceptions.class.getResource(".").getPath();
+       //RunJS.runJSFile(new String[]{resourceDir}, "multiple_assignment.js");
+       RunJS.runJSFile(new String[]{resourceDir}, "finally.js");
+
+       }
+    
+       public TestCase createTestCase(String resourceDir, String fileName) {
+               return new JavaExceptionTestCase(resourceDir, fileName);
+       }
+    
+       ////////////////////////////////////////////////////////////
+       // Test Case
+       ////////////////////////////////////////////////////////////
+       static class JavaExceptionTestCase extends JSTestCase{
+
+               public JavaExceptionTestCase(String resourceDir, String 
jsFileName) {
+                       super(resourceDir, jsFileName);
+               }
+               protected void runTest() throws Throwable {
+                       try{
+                               RunJS.runJSFile(new String[]{resourceDir}, 
main,new String[]{"testObj"}, new JS[]{new TestObj()} );
+                       }catch(JSExn e){
+                               fail(e.getMessage());
+                       }
+               }
+       }
+       
+       ////////////////////////////////////////////////////////////
+       // Test Object
+       ////////////////////////////////////////////////////////////
+       static class TestObj extends JS.Obj{
+               
+               public JS get(JS jsKey) throws JSExn {
+               String key = JSU.toString(jsKey);
+            if( "throwJavaException".equals(key)){
+                       return METHOD;
+            }
+                       return super.get(jsKey);
+               }
+               
+               public JS call(JS method, JS[] args) throws JSExn {
+               String key = JSU.toString(method);
+            if( "throwJavaException".equals(key)){
+               throw new RuntimeException("haha!");
+            }
+    
+                       return super.call(method, args);
+               }
+       }
+       
+}

Added: core/trunk/org.ibex.js/src_junit/test/js/exceptions/java/handled.js
===================================================================
--- core/trunk/org.ibex.js/src_junit/test/js/exceptions/java/handled.js         
                (rev 0)
+++ core/trunk/org.ibex.js/src_junit/test/js/exceptions/java/handled.js 
2007-03-26 14:31:27 UTC (rev 1750)
@@ -0,0 +1,11 @@
+//////
+// Test simple trap stuff
+
+try{
+    sys.testObj.throwJavaException();
+}
+catch(e){
+       sys.print(e.message);
+    var msgEnd = e.message.slice(-5);
+    assert("haha!", msgEnd);
+}

Modified: 
core/trunk/org.ibex.js/src_junit/test/js/traps_pause_on_put/TestPauseOnPut.java
===================================================================
--- 
core/trunk/org.ibex.js/src_junit/test/js/traps_pause_on_put/TestPauseOnPut.java 
    2007-03-25 07:22:28 UTC (rev 1749)
+++ 
core/trunk/org.ibex.js/src_junit/test/js/traps_pause_on_put/TestPauseOnPut.java 
    2007-03-26 14:31:27 UTC (rev 1750)
@@ -39,11 +39,12 @@
                    Log.uWarn(TestPauseOnPut.class,"Caught JS Exception while 
putting to trap \""+name+"\"");
                    Log.uWarn(TestPauseOnPut.class,e);
                    return true;
-               } catch (Exception e) {
+               }/* REMARK can only have JSExns ... TODO remove later
+                catch (Exception e) {
                    Log.warn(this,"Caught Exception while putting to trap 
\""+name+"\"");
                    Log.warn(this,e);
                    return true;
-               }
+               }*/
                return false;
                
            }
@@ -56,10 +57,11 @@
                } catch (JSExn e) {
                    Log.uWarn(TestPauseOnPut.class,"Caught JS Exception while 
putting to trap \""+name+"\"");
                    Log.uWarn(TestPauseOnPut.class,e);
-               } catch (Exception e) {
+               } /* REMARK can only have JSExns ... TODO remove later
+                catch (Exception e) {
                    Log.warn(this,"Caught Exception while putting to trap 
\""+name+"\"");
                    Log.warn(this,e);
-               }
+               }*/
            }
            ///
            // Testing pre and post putting

Modified: core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp  2007-03-25 07:22:28 UTC 
(rev 1749)
+++ core/trunk/org.vexi.core/src/org/vexi/core/Box.jpp  2007-03-26 14:31:27 UTC 
(rev 1750)
@@ -770,10 +770,11 @@
         } catch (JSExn e) {
             Log.uWarn(Box.class,"Caught JS Exception while putting to trap 
\""+name+"\"");
             Log.uWarn(Box.class,e);
-        } catch (Exception e) {
-            Log.warn(this,"Caught Exception while putting to trap 
\""+name+"\"");
-            Log.warn(this,e);
-        }
+        } /* REMARK can only have JSExns ... TODO remove later
+        catch (Exception e) {
+        Log.warn(this,"Caught Exception while putting to trap \""+name+"\"");
+        Log.warn(this,e);
+       }*/
         return null;
     }
 
@@ -792,11 +793,12 @@
             Log.uWarn(Box.class,"Caught JS Exception while putting to trap 
\""+name+"\"");
             Log.uWarn(Box.class,e);
             return true;
-        } catch (Exception e) {
-            Log.warn(this,"Caught Exception while putting to trap 
\""+name+"\"");
-            Log.warn(this,e);
-            return true;
-        }
+        } /* REMARK can only have JSExns ... TODO remove later
+        catch (Exception e) {
+        Log.warn(this,"Caught Exception while putting to trap \""+name+"\"");
+        Log.warn(this,e);
+        return true;
+       }*/
         return false;
         
     }
@@ -809,10 +811,11 @@
         } catch (JSExn e) {
             Log.uWarn(Box.class,"Caught JS Exception while putting to trap 
\""+name+"\"");
             Log.uWarn(Box.class,e);
-        } catch (Exception e) {
-            Log.warn(this,"Caught Exception while putting to trap 
\""+name+"\"");
-            Log.warn(this,e);
-        }
+        } /* REMARK can only have JSExns ... TODO remove later
+        catch (Exception e) {
+        Log.warn(this,"Caught Exception while putting to trap \""+name+"\"");
+        Log.warn(this,e);
+       }*/
     }
 
     //#repeat Width/Height width/height 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to