Fetching Full stacktrace Exceptions

I am trying to update the Apache lang dossier from 2.4 to 3.1 in my project. In my implementation, there is a link to ExceptionUtil.getFullExceptionTrace (e), which no longer exists in 3.1. Reason for deletion is indicated as

"Removing isThrowableNested, isNestedThrowable and getFullStackTrace since they were all no-op types as soon as you got into JDK 1.4. LANG-491"

. A few questions about this change:

  • I am confused if this means that we need to learn another way to get the full stack trace, otherwise we can replace ExceptionUtils.getStackTrace (e) instead.

  • Any idea on what has changed since jdk 1.4 to make the method redundant?

  • Can't we just do e.toString (), where e is my instance of Exception?

thanks

+4
source share
1 answer

Java 1.4 introduced the getCause () method for the Throwable class, which is the parent of all exception classes. If you need to get the 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 for JIRA LANG-491 issue .

+6
source

Source: https://habr.com/ru/post/1412013/


All Articles