I either write exception handlers right away or let the exceptions propagate up. I'm a big fan of what I call "You don't want to come back and fix it later, right?" principle. You say you will, but to be honest, as soon as you earn it, you will not return and correct it later, will you? Just right now! Write your exception handlers right away or add a throws and make it someone else's problem. Do the right thing right now.
But you know that, sometimes you cannot. No matter what you do, do not swallow exceptions with empty exception handlers! This evil:
try { connection.close(); } catch (Exception e) {
I am throwing someone from my team that is checking this.
If you really don't know what to do with the exception, and you can't add a throws to spread it up, at least do something half responsible. Print a stack trace if nothing else. This is not ideal, but at least you do not hide the mistakes.
catch (IOException exception) { exception.printStackTrace(); }
Logging through the application logging system is better, although you should not get used to it. He must be responsible for the calls to deal with such things.
catch (IOException exception) { log.error(exception, "Unable to open configuration file %s.", fileName); }
As a last resort, you can execute the end of your throws by wrapping your exception in a RuntimeException . At the very least, you give someone higher up in the call chain a chance to handle the error, which is usually the right thing to do.
catch (IOException exception) { throw new RuntimeException(exception); }