Browse Source

* Allow to hook uncaught exception handling

git-svn-id: trunk@45374 -
michael 5 years ago
parent
commit
ce0c43c934
1 changed files with 28 additions and 10 deletions
  1. 28 10
      utils/pas2js/dist/rtl.js

+ 28 - 10
utils/pas2js/dist/rtl.js

@@ -145,19 +145,37 @@ var rtl = {
       }
     }
     
-    if (rtl.showUncaughtExceptions) {
-      try{
-        doRun();
-      } catch(re) {
-        var errMsg = rtl.hasString(re.$classname) ? re.$classname : '';
-	    errMsg +=  ((errMsg) ? ': ' : '') + (re.hasOwnProperty('fMessage') ? re.fMessage : re);
-        alert('Uncaught Exception : '+errMsg);
-        rtl.exitCode = 216;
+    try {
+      doRun();
+    } catch(re) {
+      if (!rtl.showUncaughtExceptions) {
+        throw re
+      } else {  
+        if (rtl.handleUncaughtException(re)) {
+          rtl.showException(re);
+          rtl.exitCode = 216;
+        }  
+      }
+    } 
+    return rtl.exitcode;
+  },
+  
+  showException : function (re) {
+    var errMsg = rtl.hasString(re.$classname) ? re.$classname : '';
+    errMsg +=  ((errMsg) ? ': ' : '') + (re.hasOwnProperty('fMessage') ? re.fMessage : re);
+    alert('Uncaught Exception : '+errMsg);
+  },        
+  handleUncaughtException: function (e) {
+    if (rtl.onUncaughtException) {
+      try {
+        rtl.onUncaughtException(e);
+        return false;
+      } catch (ee) {
+        return true; 
       }
     } else {
-      doRun();
+      return true;
     }
-    return rtl.exitcode;
   },
 
   loadintf: function(module){