> whether you would use getNextException() of getCause()
> would depend on whether the underlying code that throws
> the SQLException is using the old style chaining using
> setNextException(), or the newer style using initCause().
That's one nice thing about Jakarta Commons Lang and their
ExceptionUtils class - it understands multiple chaining mechanisms and
can abstract that away for you. Their getCause and getRootCause
methods are most likely what you want for this case. Their
getFullStackTrace works nicely as a string conversion of a nested
exception.
http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/exception/ExceptionUtils.html
for the chaining methods it tries, check out the first getCause
method javadoc.
http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/exception/ExceptionUtils.html#getCause(java.lang.Throwable)
(I hope nothing wraps those url's for you, my mutt shouldn't)
As an aside, I've found log4j and Jakarta Commons Logging (even not on
top of log4j) to be very nice about nested exceptions - they look
great and only print the non-redundant stack frames. Very slick.
Also as an aside, I hate that SQLException didn't get the constructors
to make it constructor-based chainable - that's a travesty to me. As
a class, it's gone from leading the rest of the base API in chaining
ability to (IMHO) now lagging it.
Compare the constructors of
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/SQLException.html
and
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Throwable.html
To get more tangential, in my projects (and the ones where I help
dictate coding patterns, the 2-arg (string, throwable) constructor is
pretty much the only one I allow - there is the occasional situation
where I allow creation of new exceptions (like
IllegalArgumentExceptions for some run-time param checking) but
they're relatively rare - I like chained exceptions for detailing
after-the-fact what the various layers in the stack saw - stack traces
have some value, but chained exceptions that give context are better
:)
James
--
James Manning <http://www.sublogic.com/james/>
GPG Key fingerprint = B913 2FBD 14A9 CE18 B2B7 9C8E A0BF B026 EEBB F6E4
_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org