Search

AppDomain.UnhandledException does not run in all cases by SecurityException1

Closed
as Fixed Help for as Fixed

1
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 94618
Opened: 8/7/2005 3:09:25 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
If you have a Callback Method from Winforms and an unhandled Exception occurs, the AppDomain.UnhandledException will not be run. This is _very_ unpleasant behaviour, as it is impossible to write an own exception handler without placing a try-catch in _every_ callback-Method of a WinForm. This has to be fixed, please!
Details (expand)
Product Language
English
Version
Visual Studio 2005 Beta 2
Category
Other
Subcategory
 
Operating System
Windows XP Professional
Steps to Reproduce
Use the attached project to reproduce the bug.
Actual Results
There is only the message of .Net Framework and your program will get kicked. Goodbye!
Expected Results
I expect the AppDomain.UnhandledException delegate to be run.
File Attachments
0 attachments
Sign in to post a comment.
Posted by SecurityException1 on 8/7/2005 at 3:17 AM
Additional Information:

I just realized that this behaviour does not occur if you run with the debugger (Debug/Release - Build does not seem to matter). In this case, your delegate will be run (in the example, the MessageBox is shown on click). If you don't run with debugging, the custom MessageBox does not appear, so I conclude that this must be a real bug.
Of course, it's a lot more important to have your handler if you do _not_ run with the debugger attached. ;)
Posted by Microsoft on 8/8/2005 at 12:54 PM
Thank you for your feedback on this issue. By default, unhandled exceptions in a Windows Forms application will display the Unhandled Exception Dialog. You can get the behavior you want by either hooking the Application.ThreadException event (rather than the UnhandledException event) or by setting Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException) in your Main() method.

The Windows Forms Team
Posted by SecurityException1 on 8/8/2005 at 2:38 PM
I would like to request for a clearer documentation. For example, in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemappdomainclassunhandledexceptiontopic.asp there is simply no word about when an exception is candidate for raising the event and when not. There is also no link to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationclassthreadexceptiontopic.asp, in which there is also no clear statement what kind of exceptions are raising this event.

Are there any further situations where none of these two handlers will be called? Is there a default handler for all exceptions?


The second thing is that I am still wondering, why in my test project the event is raised when running with the debugger. IMHO it's somewhat confusing if the application behaves completely different when being run with the debugger or not. Especially, custom uncaught exception handling is IMHO not more important when running with the debugger than it is when running without.
Posted by Microsoft on 11/15/2005 at 12:22 PM
Updated the docs for AppDomain.UnhandledException to make it clear that by default the UnhandledException event is preempted in Windows.Forms applications by the ThreadException event, but ONLY for the UI thread. (Also mentioned that this default behavior can be overridden, so that UnhandledException is raised instead of ThreadException.) This will be available in MSDN online next time we upload updated content. Handing the bug off to WinForms to update the other topics.
Posted by Microsoft on 1/11/2006 at 3:50 PM
Updated the ThreadException sample to (1) use SetUnhandledExceptionMode() and (2) show handling errors generated in both Windows Forms main UI thread (ThreadException) and in other threads (AppDomain.UnhandledException). Added new explanatory text to differentiate the two.
Posted by Microsoft on 1/16/2006 at 12:30 PM
Updated the ThreadException sample to (1) use SetUnhandledExceptionMode() and (2) show handling errors generated in both Windows Forms main UI thread (ThreadException) and in other threads (AppDomain.UnhandledException). Added new explanatory text to differentiate the two.

Added sample to App.ThreadException, App.SetUnhandledExceptionMode (all overloads), and UnhandledExceptionMode enum.