locked
How to continue execution after an exception? RRS feed

  • Question

  • 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, November 22, 2006 7:18 AM

Answers

  • 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, November 29, 2006 9:52 PM

All replies

  • 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.

    Wednesday, November 22, 2006 6:32 PM
  • 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

    Thursday, November 23, 2006 3:50 AM
  • 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, November 29, 2006 9:52 PM
  • Lifeng,

    Thanks for your help.  It works.

    Stanley

    Wednesday, January 3, 2007 9:11 AM