What is a First Chance Exception?

来源:互联网 发布:mac装win10无线 编辑:程序博客网 时间:2024/05/22 17:17

David Kline

 

source:http://blogs.msdn.com/davidklinems/archive/2005/07/12/438061.aspx

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 isbeing debugged, the debugger gets notified whenever an exception isencountered  At this point, the application is suspended and thedebugger decides how to handle the exception. The first pass throughthis mechanism is called a "first chance" exception. Depending on thedebugger's configuration, it will either resume the application andpass the exception on or it will leave the application suspended andenter debug mode. If the application handles the exception, itcontinues 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

InVisual Studio 2005 Beta2, you will see this message anytime a firstchance exception is encountered in your application's code.  If you areusing Visual Studio .NET 2003, this message is shown if you haveconfigured the debugger to stop when the specific exception type isthrown.

If the application does not handle the exception, thedebugger is re-notified. This is known as a "second chance" exception.The debugger again suspends the application and determines how tohandle this exception. Typically, debuggers are configured to stop onsecond 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?
Firstchance exception messages most often do not mean there is a problem inthe code. For applications / components which handle exceptionsgracefully, first chance exception messages let the developer know thatan exceptional situation was encountered and was handled.

Forcode without exception handling, the debugger will receive a secondchance 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.
Someof the information contained within this post may be in relation tobeta software. Any and all details are subject to change.

PublishedTuesday, July 12, 2005 11:16 AMbyDavidKlineMSFiled under: Debugging

原创粉丝点击