开发者

Visual Studio Debug Mode, Allow Exception to Kill the Program

I have a piece of code in C# that's essentially like the following...

WriteFile();
try {
    RunTest();
} finally {
    DeleteFile();
}

Now this has been planned so that even on failure, it cleans up the files it left behind. This works when not run in debug mode (although it pops up a message asking if I want to debug the program or close it. Closing it produces the appropriate results).

When I run this in debug mode and hit an exception inside of RunTest, I only seem to have two options. In the first one, I t开发者_Python百科ell debugging to stop. This is equivalent to killing the program and the block in finally does not run (so the file doesn't get deleted like it should). If I tell it to continue, it doesn't propogate the exception up and instead, it just hits an exception somewhere else.

Is there anyway to get debug mode to continue like a normal program after hitting an exception?


From the Debug menu, choose Exceptions (or use Ctrl + Alt + E). This will bring up a dialog where you can uncheck appropriate checkboxes in the "User-unhandled" column for exceptions which you don't want to stop at while debugging. I believe that will make exception propagation work normally. And you can still set a breakpoint either in the try or finally block to see what's happening.


Check Debug/Exceptions if there are any exceptions set.

Another option would be to handle the event Application.ThreadException (Windows Forms) or Application.UnhandledException (Silverlight etc.) and tell the application to continue or exit, depending on the severity of your exception.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜