[Mono-devel-list] Hidden Exceptions

Jonathan Pryor jonpryor at vt.edu
Wed Feb 16 07:04:52 EST 2005

On Wed, 2005-02-16 at 03:14 -0500, Sébastien Robitaille wrote:
> I discovered that there are 3 exceptions that are always thrown when
> starting any application (even a small "Hello World" program).
> The exceptions are the following:
> [1] System.OutOfMemoryException: Out of memory
> [2] System.NullReferenceException: A null value was found where an
> object instance was required
> [3] System.StackOverflowException: The requested operation caused a
> stack overflow.

These exceptions aren't thrown, they're constructed.  There's a
difference. :-)

Why are they constructed?  So that they always exist so they can be
thrown.  For example, if you're out of memory, can you really expect to
construct a new OutOfMemoryException object to throw?  No, so you create
it at program startup and cache it for when you need it.  The same is
similarly true for NullReferenceException and StackOverflowException.

> I was wondering if these were "real" exceptions or not... Any idea ?

Yes, they're real, and they're not thrown.

> BTW, Is there a better way to print the exceptions thrown by a program
> running under mono, without interfering with the execution of
> the program?

You could try using the --breakonex and --trace arguments to mono.  I
haven't tried them, but it looks like this should work:

	mono --trace=T:System.Exception app.exe

 - Jon

More information about the Mono-devel-list mailing list