catch { // Nothing but whitespace } should be banned!

Before I get started, I need to state that I don’t agree with Joel’s condemnation of the try {} catch {} block. My beef is with the catch {} block, or more specifically with empty catch blocks like this.



    // Code that may throw an exception.


catch (SomeException ex)


    // Sweep exception under the rug.


The problem here is that I am catching an exception but doing nothing with it. Not a single diagnostic, nothing, but it is surpising how often I’ve seen this code even in C# where there are no checked exceptions! This code can make bugs impossible to hunt down because silently ignoring an exception can result in side effects an completely different branches of execution.

There are a number of other enhancements that I’d like to see made to the exception handling syntax in C#, but I’ll leave them for a later post.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s