Search code examples
cexceptionmonoembedding

Catch an exception in embedded mono


MonoObject * pException = NULL;
// this method will cause an exception in c#, something like null exception
MonoString * pResult = (MonoString*) mono_runtime_invoke(g_pGetMethod, NULL, monoargs, &pException);  
/* debugging with gdb:
    (gdb) n
    Program received signal SIGPWR, Power fail/restart.
    then this program stopped.
*/
char * szResult = NULL;
if(pException == NULL)
{
    szResult = mono_string_to_utf8(pResult);
} else
{
    //MonoString * pMsg = mono_object_to_string_ex(pException, NULL);
    //szResult = mono_string_to_utf8(pMsg);
    szResult = "Mono throwed an Exception!";
}

i'm trying to catch MonoException like the above,
is there something i've mistaken?
g_pGetMethod is a static function btw, these code works correctly if no exception thrown


Solution

  • You should instruct gdb to ignore SIGPWR (and a few more signals):

    handle SIGXCPU SIG33 SIG35 SIGPWR nostop noprint
    

    More information about debugging Mono with gdb can be found here: http://www.mono-project.com/docs/debug+profile/debug/