tags:

views:

34

answers:

2

Hello! I'd like to show a form (the form has a box where you type in what you were doing to make the error occur, etc. and a send button to report the error to my website) when an unhandled exception occurs. As it is now, the form shows up but none of the controls draw (they are all white boxes) and then I get the "Yaya.exe has stopped responding blah blah blah".

Is there any way to keep the form up while an exception is occurring in the main thread? I've tried putting the form in it's own thread and still not helping. The exception I'm testing this with is a button that starts a backgroundworker, I keep pressing it until it throws the exception which starts the form

+2  A: 

You can wrap the contents of your main() method in a try/catch block. Show your error reporting form, log what you need to, etc. and then die.

This is a good practice regardless. It really does make the user feel slightly better to be presented with something that acknowledges the problem rather than just crashing. Of course, I say slightly better, crashes suck regardless.

Ed Swangren
Actualy, you can't wrap Main itself. You mean it's contents.
Henk Holterman
Sorry, yes, fixed.
Ed Swangren
This doesn't work out of the box. There's a default exception handler in the message loop, preventing it from ever getting to the catch clause in Main(). Application.ThreadException is raised. WPF has a very similar approach, Dispatcher.UnhandledException. And of course it cannot handle exceptions raised in worker threads.
Hans Passant
+1  A: 

There is some info on global exception handlers here:

http://stackoverflow.com/questions/3963542/uncatchable-net-runtime-2-0-error-user-machine-what-next

Basically, you have to register two events, one for appdomain exceptions, and other for thread exceptions, then implement handlers for them.

Daniel Mošmondor
This is how I have it set up, and the handlers launch the error reporting form which doesn't display.
Contra