From: Thomas Geymayer Date: Sun, 13 Oct 2013 09:37:17 +0000 (+0200) Subject: cppbind: Catch exceptions before reaching C code. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=370a99120898a46a60430db210a07411b827bc25;p=simgear.git cppbind: Catch exceptions before reaching C code. --- diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index 2732c3a1..ac844967 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -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(); } }; diff --git a/simgear/nasal/cppbind/detail/to_nasal_helper.cxx b/simgear/nasal/cppbind/detail/to_nasal_helper.cxx index 8e6e22b6..5c877e47 100644 --- a/simgear/nasal/cppbind/detail/to_nasal_helper.cxx +++ b/simgear/nasal/cppbind/detail/to_nasal_helper.cxx @@ -84,7 +84,21 @@ namespace nasal { free_function_t* func = static_cast(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(); } //----------------------------------------------------------------------------