Exceptional Eclipse Tip

By default, when eclipse creates a try/catch block for you, you end up with something like this:

  try {
  catch (EvilException e) {
    // TODO auto-generated catch block.

This is worse than useless, as it (effectively) covers up the exception1. A far better default choice is to wrap the checked exception in a RuntimeException if you don’t know what to do with it.

Thankfully, it’s fairly easy to arrange this in eclipse. Go to Preferences → Java → Code Style → Code Templates and edit the “catch block body” fragment. It should look like this:


I’m going to try and spread this around the office a bit. It should make for some slightly more robust code…

1 Please don’t remind me that it comes out on the console—people are very good at ignoring that.

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 )

Facebook photo

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

Connecting to %s