What is a First Chance Exception?
Have you ever been debugging an application and seen a message, in the output window, about a "First chance" exception?
Ever wondered:
- What is a first chance exception?
- Does a first chance exception mean there is a problem in my code?
What is a first chance exception?
When an application is being debugged, the debugger gets notified whenever an exception is encountered At this point, the application is suspended and the debugger decides how to handle the exception. The first pass through this mechanism is called a "first chance" exception. Depending on the debugger's configuration, it will either resume the application and pass the exception on or it will leave the application suspended and enter debug mode. If the application handles the exception, it continues to run normally.
In Visual Studio, you may see a message in the output window that looks like this:
A first chance exception of type 'System.ApplicationException' occurred in myapp.exe
In Visual Studio 2005 Beta2, you will see this message anytime a first chance exception is encountered in your application's code. If you are using Visual Studio .NET 2003, this message is shown if you have configured the debugger to stop when the specific exception type is thrown.
If the application does not handle the exception, the debugger is re-notified. This is known as a "second chance" exception. The debugger again suspends the application and determines how to handle this exception. Typically, debuggers are configured to stop on second chance (unhandled) exceptions and debug mode is entered, allowing you to debug.
Does a first chance exception mean there is a problem in my code?
First chance exception messages most often do not mean there is a problem in the code. For applications / components which handle exceptions gracefully, first chance exception messages let the developer know that an exceptional situation was encountered and was handled.
For code without exception handling, the debugger will receive a second chance exception notification and will stop with a unhandled exception.
Take care!
-- DK
Disclaimer(s):
This posting is provided "AS IS" with no warranties, and confers no rights.
Some of the information contained within this post may be in relation to beta software. Any and all details are subject to change.
Comments
Anonymous
July 12, 2005
So that's what first chance exceptions were all about.
When i'd see the text scrolling through my output...Anonymous
July 12, 2005
So that's what first chance exceptions were all about.
When i'd see the text scrolling through my output...Anonymous
July 12, 2005
 Well.. my illness on Monday was the result of (and I’m pretty confident about this) something...Anonymous
July 17, 2005
Wesner Moise talks about dynamic typing and other possible changes in store for C# 3.0.
David...Anonymous
July 18, 2005
Last week, I talked about what first chance exceptions are and mentioned that you could configure the...Anonymous
July 19, 2005
Yesterday, I talked about how to enable stopping in the debugger on first chance exceptions when using...Anonymous
July 29, 2005
A few days ago, I posted on how to configure the debugger to stop on first chance exceptions in Visual...Anonymous
December 30, 2006
PingBack from http://info.starbean.net/modules/wordpress/?p=11Anonymous
June 26, 2007
PingBack from http://www.zeroc.com/forums/bug-reports/3257-icepatch-exceptions.html#post14343Anonymous
December 28, 2007
PingBack from http://craig.dubculture.co.nz/blog/2007/12/29/debugging-w3wpexe-and-iis-application-pools/Anonymous
January 16, 2008
What is first chance exception, how to disable it in vs2005?Anonymous
October 01, 2008
What is a First Chance Exception? http://blogs.msdn.com/davidklinems/archive/2005/07/12/438061.aspxAnonymous
November 18, 2008
PingBack from http://forum.fachinformatiker.de/net/121731-system-componentmodel-win32exception-system-dll-aufgetreten.html#post1098549Anonymous
January 21, 2009
PingBack from http://www.keyongtech.com/467486-a-first-chance-exception-of