[Mono-dev] NullReferenceException thrown inside catch
Robert Jordan
robertj at gmx.net
Thu Aug 24 09:53:48 EDT 2006
Robert Jordan wrote:
> Robert Jordan wrote:
>> Hi,
>>
>> Janne Rantala wrote:
>>> I found out that when NullReferenceException is thrown inside catch
>>> clause in embedded environment, Mono crashes. Normally when method is
>>> invoked with mono_runtime_invoke, exceptions are stored in MonoObject
>>> but somehow this does not happen in this case.
>>> This happened when I tried to print out message from InnerException
>>> which didn't exist.
>>>
>>> Here is the code, without that Console.WriteLine it works ok
>>> (exception is stored in MonoObject).
>>
>> Here is another simple sample:
>>
>> public void CrashMe ()
>> {
>> null.Equals (null);
>> }
>>
>>
>> It seems that a "true" SIGSEGV (generated by native JIT code)
>> cannot be caught by mono_runtime_invoke ().
>>
>> Please file a bug, if no one objects (it could be by design).
>
> Oh, it's a Windows problem. I cannot reproduce it under Linux.
The Windows port seems to use SEH. Maybe a SEH handler
could be able to catch the exception:
#include <windows.h>
MonoException *ex;
__try {
mono_runtime_invoke ( ..., &ex);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
/* simulate a NRE */
ex = mono_get_exception_null_reference ();
}
if (ex != NULL) {
handle the exception
}
The code is for VC++ in C mode (not C++).
Robert
More information about the Mono-devel-list
mailing list