On Fri, Jun 4, 2010 at 3:55 PM, Alan D. Cabrera <list@toolazydogs.com> wro

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

> -----BEGIN PGP SIGNED MESSAGE-----
> 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.


+1
 
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.  :)


+1 - we need to find a way to make this easier to read either with the IDE's help or other. 

--
Alex Karasulu
My Blog :: http://www.jroller.com/akarasulu/
Apache Directory Server :: http://directory.apache.org
Apache MINA :: http://mina.apache.org
To set up a meeting with me: http://tungle.me/AlexKarasulu