开发者

Why can the winforms unhandled exception box sometimes continue?

I've recently switched over to handling my unhandled exceptions this way:

Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new Unhand开发者_运维知识库ledExceptionEventHandler(CurrentDomain_UnhandledException);

This will be nice for logging and what not, but I've lost the ability of the old unhandled exception box to 'continue'. My current handler just prompts for a restart. A lot of the time, clicking continue in that unhandled exception box actually keeps the program running just fine. How does this work? Is there a way I can allow 'continuing' with the way I'm catching the unhandled exceptions now? Say if the exception is of a certain type, could I attempt to 'continue' just like the unhandled exception box does? Or is this not possible?

Does anybody out there understand the nuts and bolts of the world of exceptions? Would love to hear your guys' thoughts.


The application is terminated because this is the default behaviour of CLR. If you have an exception that is unhandled, this means you have a critical flaw in your program and the best handling for such situation is to close the whole app.

There is a technique, however, if you want to continue after such unhandled exception. You can create a second domain in your application and load libraries there. Exceptions within different app domains are independent. Check out my blog entry on this, there is some sample code available.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜