I've got a coding standards meeting in just over an hour and I need a quick answer to this one.
Common wisdom among experienced Java programmers is that you don't throw or catch java.lang.Exception (with rare exceptions - no pun intended). The reason you don't do this is that the statement
catch (java.lang.Exception ex) {...}
will also catch unchecked Exceptions, and in most cases this is not what is intended.
We already have a lot of legacy code written by existing team members where they catch a subclass of java.lang.Exception, log an error, and rethrow the subclass as java.lang.Exception.
I need to convince them that
- They need to stop writing code like this.
- Existing code that uses this anti-pattern needs to be fixed
Number 2 means a fair amount of refactoring.
It will shorten the argument at the meeting if I can show an article or blog entry by one of the Java community heavyweights that makes this point (i.e. Joshua Bloch, James Gosling). My google-fu hasn't turned up anything so far.
Does anyone know of an article or blog by a respected Java guru that says that you shouldn't throw or catch java.lang.Exception?
Quick answers are much appreciated.
Dean