I have coding standards standards in just an hour, and I need a quick answer to this question.
The common wisdom among experienced Java programmers is that you don’t throw or catch java.lang.Exception (with rare exceptions, the pun is not intended). The reason you do not do this is because the statement
catch (java.lang.Exception ex) {...}
also catches unverified exceptions, and in most cases this is not what is supposed to be.
We already have a lot of legacy code written by existing team members where they catch a subclass of java.lang.Exception, register an error, and restructure the subclass as java.lang.Exception.
I need to convince them that
- They need to stop writing such code.
- Existing code that uses this anti-pattern must be fixed.
Number 2 means a fair amount of refactoring.
He will reduce the argument in the meeting if I can show the article or blog entry to one of the heavyweights of the Java community that does this (e.g. Joshua Bloch, James Gosling). My google-fu hasn't added anything yet.
Does anyone know an article or blog from a reputable Java guru that says you shouldn't throw or catch java.lang.Exception?
Quick replies are much appreciated.
Dean
java exception-handling
Dean schulze
source share