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.
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