]> git.mxchange.org Git - simgear.git/commitdiff
cppbind: Catch exceptions before reaching C code.
authorThomas Geymayer <tomgey@gmail.com>
Sun, 13 Oct 2013 09:37:17 +0000 (11:37 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 13 Oct 2013 09:40:27 +0000 (11:40 +0200)
simgear/nasal/cppbind/Ghost.hxx
simgear/nasal/cppbind/detail/to_nasal_helper.cxx

index 2732c3a1c663648269b48995a5cd6ad53be770bb..ac8449673298dbabc2e90a40a6afd6a328bde7b6 100644 (file)
@@ -233,11 +233,24 @@ namespace nasal
             if( !holder )
               naRuntimeError(c, "invalid method holder!");
 
-            return holder->_method
-            (
-              requireObject(c, me),
-              CallContext(c, argc, args)
-            );
+            try
+            {
+              return holder->_method
+              (
+                requireObject(c, me),
+                CallContext(c, argc, args)
+              );
+            }
+            catch(const std::exception& ex)
+            {
+              naRuntimeError(c, "Fatal error in method call: %s", ex.what());
+            }
+            catch(...)
+            {
+              naRuntimeError(c, "Unknown exception in method call.");
+            }
+
+            return naNil();
           }
       };
 
index 8e6e22b639a74d5b1a3fb46188b78e3526d95618..5c877e47dd36f4f5ca988ccd7ce55dcfe02f74c6 100644 (file)
@@ -84,7 +84,21 @@ namespace nasal
   {
     free_function_t* func = static_cast<free_function_t*>(user_data);
     assert(func);
-    return (*func)(nasal::CallContext(c, argc, args));
+
+    try
+    {
+      return (*func)(nasal::CallContext(c, argc, args));
+    }
+    catch(const std::exception& ex)
+    {
+      naRuntimeError(c, "Fatal error in Nasal call: %s", ex.what());
+    }
+    catch(...)
+    {
+      naRuntimeError(c, "Unknown exception in Nasal call.");
+    }
+
+    return naNil();
   }
 
   //----------------------------------------------------------------------------