MSDN > 論壇首頁 > Visual Studio Debugger > How to continue execution after an exception?
發問發問
 

已答覆How to continue execution after an exception?

  • Wednesday, 22 November, 2006 7:18Stanley Chou_ 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    hi,

    Sometimes I need to end the current process without reporting an error in my windows application, so I design an AbortException class and handle this exception in Application.ThreadException event.  It works like a "silent exception".  Everytime I need to stop a process without showing a message, I throw an AbortException.  But it is really a problem when I need to continue debugging after this exception.  Does anyone know how to avoid the Exception dialog box from reappearing?  I found a related topic on http://msdn2.microsoft.com/en-us/library/ky9bw27e.aspx but it didn't help...

    Thanks.

    Stanley

解答

  • Wednesday, 29 November, 2006 21:52Lifeng Lu - MSFT版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    Yes, it is expected.  The reason is the exception event handler is disabled, when you run it under debugger. That is by-design to help debugger to stop on unexpected exceptions. With the exception event handler, you would catch all exceptions, so you would miss a bug, if your code causes, for example, a NullReference exception.

    Of course, in your scenario, the exception is expected. Unfortunately, there is no way to disable this behavior (which is done in the framework code in your application.) 

    You can try to start your application in non-debug mode, (start it out of the Visual Studio), and attach the debugger to your application after this.  That will make the application to think there is no debugger attached when it starts, so your event handler could work.

    Thanks

     

所有回覆

  • Wednesday, 22 November, 2006 18:32Azeem Khan - MSFTMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Stanley,

    I assume you are talking about the Exception Assistant (EA) dialog that comes up. The EA causes an unwind to the point just before exception gets thrown. So continuing will cause exception to be thrown again. You can disable this behavior by disabling Tools -> Options -> Debugging -> General -> Unwind callstack on unhandled exception or you can disable Exception Assistant itself. This should let you continue from unhandled exceptions.

    If you have stopping on first-chance exceptions enabled (see Debug -> Exceptions, Thrown column) then debugger will stop when an exception is thrown but you should be able to continue.  You can disable this as well from the Exceptions dialog. Note that the debugger always stops for unhandled exceptions but you can continue if you have above EA option or EA disabled. HTH.

    Azeem Khan

    Visual Studio Debugger.

  • Thursday, 23 November, 2006 3:50Stanley Chou_ 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Azeem,

    Thanks for your help.  It seemed that the debugger acted a little different after disabling "Unwind call stack on unhandled exceptions" option.  The Application just terminated when I clicked Continue on my AbortException.  Is it normal?  What can I do if I want it ignore this exception and behave like it is executed independently?  Because I really don't want to restart debugging each time when this exception thrown.  Thanks.

    Stanley

  • Wednesday, 29 November, 2006 21:52Lifeng Lu - MSFT版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    Yes, it is expected.  The reason is the exception event handler is disabled, when you run it under debugger. That is by-design to help debugger to stop on unexpected exceptions. With the exception event handler, you would catch all exceptions, so you would miss a bug, if your code causes, for example, a NullReference exception.

    Of course, in your scenario, the exception is expected. Unfortunately, there is no way to disable this behavior (which is done in the framework code in your application.) 

    You can try to start your application in non-debug mode, (start it out of the Visual Studio), and attach the debugger to your application after this.  That will make the application to think there is no debugger attached when it starts, so your event handler could work.

    Thanks

     

  • Wednesday, 3 January, 2007 9:11Stanley Chou_ 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Lifeng,

    Thanks for your help.  It works.

    Stanley