directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alan D. Cabrera" <>
Subject Re: Exception Logging
Date Fri, 04 Jun 2010 12:55:54 GMT

On Jun 3, 2010, at 2:15 PM, Felix Knecht wrote:

> Hash: SHA1
> We have a lot of following constructs:
> log.error( I18n.err( I18n.ERR_04007 ) );
> throw new DecoderException( I18n.err( I18n.ERR_04007 ) );
> What about logging the exception within the exception itself like
> public DecoderException(String message)
> {
>    super( message );
>    log.error( message );
> }
> This will avoid having log.error all over the place and the translation
> must be done only once instead of twice like above.

This is not a very good pattern for a number of reasons.

First, you cannot control logging at the source of the error.  Admittedly this is an error
message but I have run into times where I want to turn off the klaxon to see what the real
problem is.

Second, constructors should not have side effects.  It's never a good idea.

Third, I never log an error if I am throwing an exception.  It just adds noise.  I will, however,
log additional useful information that is not in the exception message.  Just parroting what's
in the exception is of little value.

Finally, what the heck is ERR_04007? :)  I thought there already was a discussion and community
consensus about how there is little to negative value in using numbers as error messages.
 Maybe I missed the conversation where this opinion was reversed.  If so, ignore this bit.


View raw message