I am trying to upgrade Apache commons lang from 2.4 to 3.1 in my project. My implementation has a reference to ExceptionUtil.getFullExceptionTrace(e) which does not exist anymore in 3.1. The reason of removal was listed as
"Removing isThrowableNested, isNestedThrowable and getFullStackTrace as they were all types of no-op once you got to JDK 1.4. LANG-491"
. Few questions around this change:
I am confused if this means we need to explore some other way to retrieve full stack trace or we can simply replace with ExceptionUtils.getStackTrace(e) instead.
Any idea on what changed after jdk 1.4 to make the method redundant?
Can't we simply do e.toString() where e is my Exception instance?
Thanks
Java 1.4 introduced getCause() method on Throwable class which is a parent for all Exception classes. If you need to get a stack trace as a String, you can use ExceptionUtils.getStackTrace(e) or something like this:
Exception e = ...
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String stack Trace = sw.toString();
See additional discussion about removing methods from ExceptionUtil on JIRA issue LANG-491.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With