First-Chance Exceptions

Sloppy code might be swallowing exceptions improperly without decent handling. When you see source code that looks like this, you should start to shiver:

try {    // Exception raised here.}catch (SomeException) { }

At the same time, consider yourself lucky you saw the code to begin with. Much more likely you’re finding yourself back in a situation where you need to find out why the program misbehaves under certain circumstances. Assuming the preceding code lies at the heart of the observed misbehavior, the question becomes how to track it down. After all, the exception might long have been swallowed, and the program may crash in some different corner. Consider the following example:

static ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.