Vladimir R. Bossicard wrote:
While browsing the code (and trying to understand it) I've seen a lot of code like this one:
public void methodname() throws XMLDBException { code_that_can_throw_exeception; }
Should we encapsulate the call between a try/catch block, like this:
public void methodname() throws XMLDBException { try { code_that_can_throw_exeception } catch (Exception e) { throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e); } }
To respect the signature (and since we have chained exceptions)? This is of course only applicable for unchecked exceptions.
I've worked quite a bit with exceptions in cocoon, so here are my 2c of wisdom.
- never ever catch an exception just to rethrow it.
- if you rethrow it, deal with it, log it, and chain it.
- make the exception be catched possibly always in the same point, which is usually somewhere down the base of the program call stack.
- never incapsulate exceptions in an exception that is generic for the project. It kills all the semantics in it with no gain.
- if you are catching "Exception", please look yourself in the mirror first and ask yourself if you're really a Java developer ;-)
Ciao!
--
Nicola Ken Barozzi [EMAIL PROTECTED]
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------