Craig,
Thanks for the example, although you didn't have to. I'll look up
Effective Java. The problem with doing a printStackTrace() for each
exception in the causation chain, is that the exceptions share part of the
stack trace, and this of course drives us all mad, seeing the same 20
function calls over and over again. There are three possibilities to avoid
this situation:
1. Avoid catching and throwing another exception. Probably not possible
for JBoss which must follow well defined interfaces.
2. At the point of logging, write something like this:
logger.error( makeDetailedMessage("Caught some error", e), e );
static String makeDetailedMessage( String firstMsg, Exception e ) {
String s = firstMessage;
for ( Exception ex = e; ex != null; ex = ex.getCause()) {
s = s + "\nCause: " + ex.toString();
}
return s;
}
In this case, we only get the stack trace from the point of the last
exception to be thrown, but we do get details of the nested exceptions,
but no stack traces for them.
3. At the point of logging, write something like:
logger.error( makeDetailedMessage( "Caught some error", e ),
getRootCause(e));
static Exception getRootCause(Exception e) {
while ( e != null && e.getCause() != null ) e = e.getCause();
return e;
}
Thus, we get the full stack trace, plus all the causes. One final, but
difficult "improvement", would be to interleave the cause messages in the
stack trace anywhere an exception was caught and another thrown. That's
probably asking for too much.
Dain, yes, I appreciate that 1.3 has to be supported for many more years.
At least org.jboss.util.NestedThrowable follows the 1.4 Throwable names.
Ciao,
Jonathan O'Connor
Ph: +353 1 872 3305
Mob: +353 86 824 9736
Fax: +353 1 873 3612
"Demyanovich, Craig - Apogent" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
13.11.2002 18:45
Please respond to jboss-user
To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
cc:
Subject: RE: [JBoss-user] Better exception logging (Was: TX Bug:
Transacti on
failure not passed back to the client)
> We really can't use the 1.4 exception class because we need
> to support
> 1.3 for a long time.
>
> -dain
At my place, we write exception classes patterned after the changes to SDK
1.4.x so that we can use them in either 1.3.x or 1.4.x. We based our work
on Item 43 of Joshua Bloch's _Effective Java_. You just need to support
the
constructors that take a cause as a parameter and add a getCause() method.
I will create an example or find an existing one and send it along later.
Craig
-------------------------------------------------------
This sf.net email is sponsored by: Are you worried about
your web server security? Click here for a FREE Thawte
Apache SSL Guide and answer your Apache SSL security
needs: http://www.gothawte.com/rd523.html
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user
-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing
your web site with SSL, click here to get a FREE TRIAL of a Thawte
Server Certificate: http://www.gothawte.com/rd524.html
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user