cppbind: Catch exceptions before reaching C code.

This commit is contained in:
Thomas Geymayer
2013-10-13 11:37:17 +02:00
parent 6deb77dd4d
commit 370a991208
2 changed files with 33 additions and 6 deletions

View 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();
}
};

View 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();
}
//----------------------------------------------------------------------------