« UKReg - Attention to Detail | Main | Announcing: SiteVista Email Testing! »

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

Testing comment spam system.

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

Post a comment


Contact Me

If you'd like to get in touch, contact me on +447944 353544 or matt@mattbrindley.com

products

Litmus

Litmus makes compatibility testing easier for web pages and email newsletters.

ThinkFold

Online outlining, for groups. Collaborate in realtime with colleagues!

Delicious Presentation Creator

20 slides from your Delicious feed, 20 seconds each.

Flare

A site-specific browser for 37Signals' Campfire chat app, bring Campfire to your desktop.

CSSVista

Edit your CSS code live in both Internet Explorer and Firefox simultaneously.