Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling Unhandled Exceptions from Winforms components in WPF

My application is built in WPF but it includes some WinForms components that we have written. When an exception is unhandled in one of the WinForms components it crashes the application.

I have implemented DispatcherUnhandledException for WPF events. This is good because it allows me to display an error and mark the exception as Handled to avoid the crash.

Can I do something similar with the non-WPF exceptions. I was hoping for the standard WinForms dialog that used to come up and allow the user to continue or quite the application?

Edit: WinForms exceptions do get caught in DispatcherUnhandledException but setting e.Handled to true doesn't stop the application from crashing.

like image 467
Alan Spark Avatar asked Nov 13 '11 11:11

Alan Spark


1 Answers

Have you tried System.Windows.Forms.Application.ThreadException and System.Windows.Forms.Application.SetUnhandledExceptionMode ?

like image 131
bitbonk Avatar answered Sep 21 '22 15:09

bitbonk