Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF custom error-handling dialog box?

I am trying to set up my WPF application so that when an exception goes unhandled, an error dialog pops up. In good ol' WinForms this was possible by adding

Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

To your Program.cs file and then showing whatever dialog you wanted in the event handling code. In WPF I've tried to use

app.Dispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);

However, when I use Show() on my error-handling custom window, the application immediately goes to "blahblah.exe has stopped working..." and closes. If I use ShowDialog(), the window is usable until it's closed and then the same "...has stopped working..." dialog pops up and dies.

In WinForms, it seems that closing any error dialog would allow the app to continue running, depending on how severe the exception was. I can't seem to figure out how to properly do this in WPF.

Any ideas?

like image 565
Eric Smith Avatar asked Apr 26 '09 17:04

Eric Smith


1 Answers

You'll need to set Handled to true in the EventArgs.

like image 151
Botz3000 Avatar answered Sep 18 '22 18:09

Botz3000