Microsoft Developer Network > Página principal de foros > Visual Studio Debugger > How to continue execution after an exception?
Formular una preguntaFormular una pregunta
 

RespondidaHow to continue execution after an exception?

  • miércoles, 22 de noviembre de 2006 7:18Stanley Chou_ Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    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

Respuestas

  • miércoles, 29 de noviembre de 2006 21:52Lifeng Lu - MSFTModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    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

     

Todas las respuestas

  • miércoles, 22 de noviembre de 2006 18:32Azeem Khan - MSFTMSFT, ModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    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.

  • jueves, 23 de noviembre de 2006 3:50Stanley Chou_ Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    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

  • miércoles, 29 de noviembre de 2006 21:52Lifeng Lu - MSFTModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    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

     

  • miércoles, 03 de enero de 2007 9:11Stanley Chou_ Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    Lifeng,

    Thanks for your help.  It works.

    Stanley