Good catch.  I recently added the log.warn(e) because in way too many
places, there was *nothing* in the catch.  I didn't realize the log api
worked that way.

When you get time, feel free to make any improvements you like, and
attach your patch to a bugzilla issue.

Thanks!

Kevin Ross

-----Original Message-----
From: Mario Cormier [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 11, 2003 10:28 AM
To: [EMAIL PROTECTED]
Subject: Logging exceptions without a message

Working with Xindice, I sometimes get a bunch of lines in my log that 
look like:

    15827 [Thread-32] WARN indexer.ValueIndexer  - 
java.lang.NullPointerException

without any stack trace available.  Now this isn't very useful when 
trying to figure out what went wrong and where.  The problem stems (I 
assume) from a small misunderstanding regarding the logging API.  You 
*can* pass an Exception as the only parameter to methods like 
Log.warn(), but they won't be interpreted as Exceptions:  they'll be 
treated just like any other Object, and the logging system will simply 
call .toString() on them and log the result and nothing more.

So it turns out that changing:

                    try {
                        // ...
                    } catch (Exception e) {
                        log.warn(e);
                    }
to:
                    try {
                        // ...
                    } catch (Exception e) {
                        log.warn("", e);
                    }

would already be a big improvement, and of course having a meaningful 
description instead of "" would be even better. :)   I could roll up my 
sleeves and submit a patch later on if you guys are interested, but 
unfortunately I can't get on it right away.  This thing called "work" 
getting in the way. :)

Keep up the great work!

Mario
_________________________
Mario Cormier
Miranda Technologies Inc.
http://www.miranda.com/

Reply via email to