We have a VB.Net project recently upgraded to 2005 and are attempting to setup our Global Error Handler using the MyApplication_UnhandledException event in the ApplicationEvents.vb class but the code for the event does not fire. Here is the testing code we are using just to test the event but it does not fire.
--------------------------------------------------------------------------------------------------------------
Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
MessageBox.Show(e.Exception.ToString)
e.ExitApplication = False
End Sub
--------------------------------------------------------------------------------------------------------------
The unusual thing is is that the MyApplication_StartUp code works fine inside the same class.
Any Ideas?
Tx
J
|
| JaysonM Wednesday, February 22, 2006 1:49 AM |
Make sure you are not debugging your application. If you debug your application, Winforms will not enable exception handling so that they will be caught by the debugger. You can change this behavior by setting Application.SetUnhandledExceptionMode.
|
| Benjamin Wulfe - MS Wednesday, February 22, 2006 2:10 AM |
Is your code multi threaded ? If so, there's another event handler to catch exceptions on other threads to the main one.
|
| cgraus Wednesday, February 22, 2006 1:53 AM |
No- we havent gone down the multithreading path as yet but are considering it in the long term so knowing the other other event handler would be useful but with the current problem - Nowe aren't multithreading. |
| JaysonM Wednesday, February 22, 2006 2:01 AM |
Make sure you are not debugging your application. If you debug your application, Winforms will not enable exception handling so that they will be caught by the debugger. You can change this behavior by setting Application.SetUnhandledExceptionMode.
|
| Benjamin Wulfe - MS Wednesday, February 22, 2006 2:10 AM |
That worked - many thanks! 
I didn't use the SystemExceptionMode though - just tested in release.
Tx
J
|
| JaysonM Wednesday, February 22, 2006 5:32 AM |
Can you elaborate on this a little?
Are you saying you can debug MyApplication_unhandledException code by setting the "setunhandledExcpetionMode"? If so, how do you set it and what do you set it to?
Thanks for your help. |
| kaebischer Monday, May 14, 2007 3:01 PM |
Well, after for searching for an answer to this for 2 days, I post the question here and within minutes find the solution myself!
I was able to debug the applicationEvents by building a "debug" version of the app, running the exe and then attaching to it (Tools/Attach to process) from the IDE with the application opened.
Worked like a champ and I found my problem in seconds.
|
| kaebischer Monday, May 14, 2007 4:28 PM |
I am using multithreading and when an exception occours there i am unable to handle the exception with the applicationEvents class, could you please let me know which handle to use to catch these exceptions
|
| QC_Ty Sunday, November 02, 2008 5:32 PM |
Is your code multi threaded ? If so, there's another event handler to catch exceptions on other threads to the main one.
I'm also interested to know what that event handler is too... Anyone know? |
| nizmo Wednesday, April 29, 2009 4:49 AM |