
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
414
|
Chapter 7: Exception Handling
7.15 Breaking on a First-Chance Exception
Problem
You need to fix a problem with your code that is throwing an exception. Unfortu-
nately, an exception handler is trapping the exception, and you are having a tough
time pinpointing where and when the exception is being thrown.
Forcing the application to break on an exception before the application has a chance
to handle it is very useful in situations in which you need to step through the code at
the point where the exception is first being thrown. If this exception were thrown
and not handled by your application, the debugger would intervene and break on the
line of code that caused the unhandled exception. In this case, you can see the con-
text in which the exception was thrown. However, if an exception handler is active
when the exception is thrown, the exception handler will handle it and continue on,
preventing you from being able to see the context at the point where the exception
was thrown. This is the default behavior for all exceptions.
Solution
Select Debug ➝ Exceptions within Visual Studio 2005 to display the Exceptions dia-
log box (see Figure 7-1). Select the exception from the tree that you want to modify
and then click on the checkbox in the Thrown column in the list view. Click the OK ...