[Mono-dev] NullReferenceException thrown inside catch

Janne Rantala janne.rantala at gmail.com
Thu Aug 24 08:28:21 EDT 2006


Hi,

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).

namespace ExceptionTest
{
    class Program
    {
        public static void Main()
        {
            try
            {
                throw new Exception("Test");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.InnerException.Message);
                throw new Exception("Testi2");
            }
        }
        public Program()
        {

        }
    }
}

Same program ran from the command line gives

"Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object"

Cheers,
Janne



More information about the Mono-devel-list mailing list