Monday, November 16, 2009

MFC and the disappearing crashes

We've had a strange problem at work with our biggest MFC app. For some reason, crash-worthy bugs (like a write to a NULL pointer) would not show up in the debugger. Instead, whenever something bad would occur, we'd get booted back to the event loop. Even when stepping in the debugger, you'd be going along and suddenly--wham--your stack would be popped and that would be that. The only evidence would be a "First chance exception" message in the Output pane. Quite frustrating when trying to catch certain types of error.

I found that this is because the MFC headers include structured exception handling which magically consumes and hides your errors. Which is the opposite of what we want, but that's how it is. Fortunately, there's a way to make the debugger cooperate. In the Debug menu, choose "Exceptions" and enable every item in "Win32 Exceptions". Voila--the debugger will stop as soon as an error occurs. Why this isn't the default is beyond me.

No comments:

Post a Comment