views:

298

answers:

2

I'm working on a .NET 4.0 Beta 1 application. When the app its run without a debugger attached and there an unhandled exception occurs, the application crashes without never showing the Unhandled Exception dialog (the one that showed the callstack and the exception that was thrown).

I understand this behavior is desirable in production, but right now I'm trying to debug some nasty bugs that are happening when the debugger is not attached.

Is there a way to make this dialog box appear when there is an unhandled exception?

Thanks

EDIT: This is a WPF application. Right now I'm listening to the UnhandledException event, but after the application finishes executing the handler, it will still crash. The dialog gave the option of continuing (one of the things I'm interested in is that).

A: 

Try attaching a handler to the Application.ThreadException (for Windows Forms applications) and/or to the System.AppDomain.CurrentDomain.UnhandledException (for Console applications).

Anax
+1  A: 

If it is a winforms app then you could setup an error handler for the AppDomain to catch/handle all uncaught exceptions.

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

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
  //deal with e.ExceptionObject for info
}
Quintin Robinson
The application is coded in WPF
Kiranu