First Chance Exception Handling in Visual Studio 2005
When working with Microsoft.mshtml I frequently find second chance exceptions are incorrectly identified as first chance if the code was called as a result of the webbrowser documentcomplete/documentcompleted event firing.
While I don't pretend to understand why this happens, I do have a workaround, which I'll explain with an example.
Your application outputs "A first chance exception of "System.InvalidCastException" has occured in app.exe", but provides no further information.
Stop debugging and, in VS2005, select the "Debug" menu, then "Exceptions...".
Now find your exception class (in this example it was under "[CLR] Exceptions" > "System" > "System.InvalidCastException") and check "Thrown" next to it so that the VS debugger will stop on this exception in future (if an exception of this type occurs for a valid reason earlier in your application, you can easily F5 over it until your reach the first chance exception).
Comments
January 22, 2007 11:44 PM
Testing comment spam system.
September 4, 2007 4:24 PM
Thank you for this tip. I used it today to troubleshoot a first chance exception I was getting with no additional information.
By turning on the Throw I was immediately able to see the line of code causing the problem.
Thanks again and good looking out!
Peace,
Daniel