From: "Adrian Crum" <adri...@hlmksw.com>
To: <dev@ofbiz.apache.org>
Sent: Thursday, May 28, 2009 8:07 PM
Subject: Re: Throwable.initCause helper method
Adam Heath wrote:
Adrian Crum wrote:
I remember you complaining a while back about developers who wrap
exceptions - because it makes code harder to debug. (I agree with that
view, btw.) Has that view changed?
try {
} catch (FooException e) {
e.printStackTrace(); // Or Debug.logError(e)
throw new BarException(e.getMessage());
}
That's what I complained about. Utility code should *never* print(or
log) an exception. It should always throw it to the calling code, and
let it decide. Of course, then you have to figure out how much is
actually utility, and how much is higher-level.
Oh. Thanks for the clarification.
Why not add a throws clause to the enclosing FreemarkerWorker method?
Because that exposes the inner workings of the method in question.
Huh?
Using your example above, the calling code could make a decision based on the exception thrown. For example, if FooException is
thrown, try an alternate method. But that decision can't be made, because FooException is never thrown.
I agree with Adrian. This is the standard way of using exceptions in Java. Of course there is still this frontier between utilities
and "main-stream code" and some part of the code have to tell what is really happening... This report also depends of who or what is
using the utility eventually. Are we missing something very special here (inner workings?) ?
Jacques
This is especially bad in some OFBiz classes where EVERY class method throws the same home-grown exception. There is no way for
calling code to know what to do when an error is encountered.
-Adrian