On May 28, 2009, at 11:26 AM, 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());
}

It's usually good to pass it up the stack, but if the Debug.logError(e) was removed (BTW, we should never have any e.printStackTrace() calls since they don't go through Log4J) then the original location of the error would be lost.

In other words, there should ALWAYS be a nested exception inside the new exception thrown. If that isn't possible then it MUST be logged, otherwise it is impossible to pin down the real source of the error (and yes, that has happened various times in the history of OFBiz...).

-David


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.

Why not add a throws clause to the enclosing FreemarkerWorker method?

Because that exposes the inner workings of the method in question.


Reply via email to