I usually do what Yoav described.

In general, I'll only log where the exception is caught and handled (not
rethrown).  Following this heuristic, if I catch the exception and throw a
different one (usually at a layer boundary), I'll log the caught exception
so that I don't lose the stack trace from where the original error occurred.

If I'm really not too sure about whether the client will properly log an
exception, I'll log it where it's originally thrown, if possible.  Doesn't
hurt to have a few extra log messages, although logging at every place where
you catch and rethrow an exception is a bad idea.  Once you start to fill up
your log with lots of duplicate information, you tend to defeat the purpose
of logging because it makes it difficult to read/consume the log files.

Ken

> -----Original Message-----
> From: Shapira, Yoav [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 17, 2004 9:00 AM
> To: Log4J Users List
> Subject: RE: RE: when to log Exceptions
> 
> 
> 
> Hi,
> 
> >Exceptions are often caught and rethrown.
> 
> If you're the end of the catching chain, i.e. if you don't rethrow it,
> log it.  If you do rethrow it, no need to log because you're 
> not really
> handling the exception.  This approach is easy and will work with
> external libraries as well, without having to throw everything as your
> own exception with meta info like hasBeenLogged.
> 
> Yoav Shapira

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to