Currently, when there is an unhandled error in one of the forms in my Windows Forms program, a dialog pops up with lots of details which are irrelevant and confusing to the end user.
I would like to replace that dialog with a more user-friendly dialog (and use a Tabbed interface to hide but make available technical details) whenever an unhandled error occurs in one of my forms.
Is there a way to replace this default dialog with a custom one?
My application is an MDI one, so if an error occurs in a form, I would like to just close out that form, show the error in a friendly way and allow them to work with other windows in the application (unless its a critical error).
A couple of ways spring to mind. Easiest one is to catch all unhandled exceptions by listening to the Application.ThreadException event
However that would simply stop the crashing and not close the mdi form. If you stop the sending thread, it would stop the mdi form altogether (it’s easier outside mdi, then the forms can run in separate threads which can be initiated sandboxed).
What I normally do is run all code sandboxed. Normally encapsulated inside an action object, but i could be a simple procedure e.g.
example call:
Running in a standard method has the added benefit of being able to control things as a wait cursor or logging. If it wasn’t an mdi environment, there would be some alternatives, but hope this one is doable.