EDIT: Actually, yes, <i>ahem</i>, I see - if e.NewItem is actually null you're going to get confused between what the problem actually is here, and that might not be repro. Perhaps I posted a little too soon... but assuming you check for that separately, the point stands :)<p>I have to disagree here - I prefer the initial code example. It's cleaner, and as soon as you get to the line of code in the debugger you'll know exactly what's up regardless of the on-the-surface-misleading null exception. So what if it's initially confusing?<p>In any case both examples are wrong, and I don't think that's made clear enough - you should be <i>actively</i> looking to check for exceptions, not passively accepting that they might happen.<p>As an aside, I've always found it cleaner to say:-<p><pre><code> var cust = e.NewItem as Customer;
if(cust == null)
throw new BlahException("blah blah blah");
cust.Save();
</code></pre>
Compared to, say:-<p><pre><code> if(!(e.NewItem is Customer))
throw new BlahException("blah blah blah");
var cust = (Customer)e.NewItem;
cust.Save();
</code></pre>
(Note that in the second case that a thread could jump in and spoil your day anyway, not to mention that .NewItem could be some crazy property which randomly decides to return null in the second case, and you'd get the same old nasty exception, as mentioned in other posts)<p>So I think the 'as' operator has value in this alone as handy sugar.<p>Obviously the real problem is that null exceptions happen at all, or that anything actually returns null, and by God is the Option discriminated union in F# a joy (union of Some/None) after dealing with all that shizzle.