Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a "first chance exception"?

What exactly is a first chance exception? How and where does it originate in a .NET program? And why is it called by that peculiar name (what 'chance' are we talking about)?

like image 678
Frederick The Fool Avatar asked Feb 19 '09 10:02

Frederick The Fool


People also ask

Whats a first chance exception?

first-chance exception (plural first-chance exceptions) (computing) An exception (error condition) when handled by a debugger, such that the programmer has the first chance to study it; such an exception would otherwise proceed to a handler or (in its absence) crash the program.

What is a second chance exception?

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.

What is an exception in Visual Studio?

Applies to: Visual Studio Visual Studio for Mac Visual Studio Code. An exception is an indication of an error state that occurs while a program is being executed.

How do I fix unhandled exception in Visual Studio?

In Visual Studio, when exceptions are thrown or end up unhandled, the debugger can help you debug these by breaking just like it breaks when a breakpoint is hit.


2 Answers

It's a debugging concept. Basically exceptions are thrown to the debugger first and then to the actual program where if it isn't handled it gets thrown to the debugger a second time, giving you a chance to do something with it in your IDE before and after the application itself. This appears to be a Microsoft Visual Studio invention.

like image 182
annakata Avatar answered Sep 22 '22 14:09

annakata


First chance exception notifications are raised when an exception is thrown. Second chance notifications are when it is not caught. (Chance – as in opportunity to break into the code in the debugger).

First and second chance exception handling

like image 29
Ian G Avatar answered Sep 22 '22 14:09

Ian G