public void doStuff() { try { doSomethingThatCouldBreak(); } catch (InvocationTargetException ite) { logger.error("Caught error", ite); handleError(ite); } catch (IOException ioe) { logger.error("Caught error", ioe); handleError(ioe); } catch (SecurityException se) { logger.error("Caught error", se); handleError(se); } }
Code like this really suggests that each of these exceptions will be a different scenario for your code. The list of potential exceptions, including RuntimeExceptions, is almost endless. If the way each exception is handled is the same don’t try to be cute picking and choosing your exceptions – catch Exception. If you catch it below the top-level of the application (which is where you normally handle exceptions that have bubbled up), you have typically got 2 things to do – log it, throw it wrapped in a RuntimeException or similar.
If you are writing more code for error handling than for functionality you are probably doing something wrong.