Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Forms Unhandled-Exception Dialog

I want to get Default Windows Forms Unhandled-Exception Dialog whenever my C# application encounters U-E. In vs 2005 when I turn off jit Debugging in app.conf like this:

<configuration>
   <system.windows.forms jitDebugging="false" />
<configuration>

the application behaves correctly and shows Windows Forms U-E default dialog, with Continue, Quit, call stack and all.

However in vs 2008, on the same machine or different, even though I diable jit I still get Default .NET Unhandled-Exception Dialog, with Debug, Send Report and Don't Send buttons.

How can I make my vs 2008 app act like the one I make in vs 2005, to show Windows Forms U-E dialog box?

Please do not recommend to use

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

just because I don't use custom handler in my vs 2005 project, why would I use in vs 2008? I want to let this job do CLR.

Any help is appreciated

like image 897
Pablo Avatar asked Apr 13 '10 12:04

Pablo


People also ask

How do you handle unhandled exception?

The . NET Framework provides a couple events that can be used to catch unhandled exceptions. You only need to register for these events once in your code when your application starts up. For ASP.NET, you would do this in the Startup class or Global.

Which event is used for unhandled exception?

The UnhandledException event is raised for unhandled exceptions thrown in other threads. Starting with Microsoft Visual Studio 2005, the Visual Basic application framework provides another event for unhandled exceptions in the main application thread. See the WindowsFormsApplicationBase. UnhandledException event.

Is unhandled exception a crash?

The reports in the Unhandled Exceptions are C# exceptions that your application is not catching in a try-catch block. These do not result in a crash (the application keeps running), but may result in unexpected behavior.

What is an Unhandled exception?

An unhandled exception is an error in a computer program or application when the code has no appropriate handling exceptions. Learn about the definition and examples of unhandled exceptions, and explore programming and exception handlers. Updated: 01/04/2022.


1 Answers

You are talking about different exception handling features. The ThreadExceptionDialog you see with the Quit and Continue buttons is triggered by the Application.ThreadException event. It will only ever appear if the exception happens on the UI thread, when an event handler that runs in response to a Windows message throws an exception. Any exception in a worker thread however will bomb the program through AppDomain.UnhandledException.

You cannot handle the latter, the program is dead and cannot continue. Displaying ThreadExceptionDialog is pointless.

You can make the program bomb consistently by disabling the ThreadException event by calling Application.SetUnhandledExceptionMode(). Now every unhandled exception will trigger AppDomain.UnhandledException and terminate the program. That's probably not what you want but is the wise choice.

Also note that the ThreadException event is disabled when you run the program with a debugger. Which is presumably why you see a difference in VS2008. There have otherwise not been any changes.

like image 158
Hans Passant Avatar answered Sep 30 '22 07:09

Hans Passant