By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,516 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

Unhandled Exception handler

P: n/a
I have a Windows forms app which is started from a sub Main. In Sub
main I have this line:

AddHandler System.AppDomain.CurrentDomain.UnhandledException, AddressOf

And I also have the method, UnhandledExceptionHandler with the proper
signature. The handler logs details of the exception to a log file as
well as sending an EMail. When I run the program through the IDE,
exceptions are caught by this handler and the appropriate logs and
emails are successfully sent.

If I run the exe directly, outside of the IDE, I get a MsgBox that says
"An unhandled exception has occurred in your application....." with a
Details, Continue and Quit buttons. When I click the Details button I
see the exception message and stack trace but for some reason my
handler does not get called. I have even attached to the process with
the debugger and set a breakpoint but it never gets hit.

Why does the code catch the error in the IDE but not when run outside
the IDE? Someone suggested to me that there was bug introduced with
version 1.1 of the framework. Does anyone have any information on



Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
To provide an example that illustrates the problem I created a Windows
Forms app with a single button. I added the following two methods to
the form class:

Private Sub UnhandledExceptionHandler(ByVal sender As Object, ByVal
e As UnhandledExceptionEventArgs)
Dim ex As Exception = DirectCast(e.ExceptionObject, Exception)
MsgBox("An Unhandled Exception has occurred: " & ex.Message)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Throw New ApplicationException("This exception is unhandled")
End Sub

I added the following statement to the constructor:

AddHandler AppDomain.CurrentDomain.UnhandledException,
AddressOf UnhandledExceptionHandler

When I run this program in the IDE and click the button, I get the
MsgBox as I expect. If I compile the app and run the .exe through
explorer and click the button, I get a notification from Windows about
the exception but my exception handler *is not called*.

Can anyone shed any light on this?

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.