Home All Groups Group Topic Archive Search About

currentDomain.UnhandledException

Author
13 Apr 2005 5:58 PM
Gary Bagen
I have copied this directly from the MSDN example into a Console
application. MyHandler does not run. Running compiled Release brings
up the JIT. What am I missing?

Module Module1

    Sub Main()
        Dim currentDomain As AppDomain = AppDomain.CurrentDomain
        AddHandler currentDomain.UnhandledException, AddressOf
MyHandler

        Try
            Throw New Exception("1")
        Catch e As Exception
            Console.WriteLine("Catch clause caught : " + e.Message)
        End Try

        Throw New Exception("2")

        ' Output:
        '   Catch clause caught : 1
        '   MyHandler caught : 2

    End Sub
    Sub MyHandler(ByVal sender As Object, ByVal args As
UnhandledExceptionEventArgs)
        Dim e As Exception = DirectCast(args.ExceptionObject,
Exception)
        Console.WriteLine("MyHandler caught : " + e.Message)
    End Sub 'MyUnhandledExceptionEventHandler

End Module

Author
15 Apr 2005 1:52 AM
Patrick Steele [MVP]
In article <8b702e36.0504130958.a53a***@posting.google.com>, garbage400
@hotmail.com says...
> I have copied this directly from the MSDN example into a Console
> application. MyHandler does not run. Running compiled Release brings
> up the JIT. What am I missing?

The VS.NET debugger gets the first chance at the exception.  When given
the option to "Debug" or "Continue", click "Continue" and your handler
will get called.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele