开发者

Starting a Form when an Exception occurs

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 con开发者_如何学JAVAtrols 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


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.


There is some info on global exception handlers here:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜