Galin Iliev's blog

Software Architecture & Development

1st and 2nd chance exceptions

On last Sofia.NET UG meeting were discussed also first and second chance exceptions which was new to me. Here is what MS Knowledge Base says on the subject:

"When an exception is raised, the handler may correct or ignore the condition rather than allow a failure to propagate up through intervening layers. This is very useful in complex environments such as networks where partial failures are expected and it is not desirable to fail an entire operation just because one of several optional parts failed. In this case, the exception can be handled so that the application does not recognize that an exception has occurred.

However, if the application is being debugged, the debugger sees all exceptions before the program does. This is the distinction between the first and second chance exception: the debugger gets the first chance to see the exception (hence the name). If the debugger allows the program execution to continue and does not handle the exception, the program will see the exception as usual. If the program does not handle the exception, the debugger gets a second chance to see the exception. In this latter case, the program normally would crash if the debugger were not present."

Comments (1) -

  • Martin Kulov

    10/19/2007 7:37:47 PM | Reply

    Here is one very old and very extensive article describing SEH (Structured Exception Handling) which .NET is using internally.

    "A Crash Course on the Depths of Win32™ Structured Exception Handling"
    www.microsoft.com/.../exception.aspx

Loading