I have the following code:
import org.apache.commons.lang.exception.ExceptionUtils; public void myMethod() { try { // do something } catch (Exception e) { System.out.println(ExceptionUtils.getStackTrace(e)); // prints "java.lang.NullPointerException" System.out.println(ExceptionUtils.getFullStackTrace(e)); // prints "java.lang.NullPointerException" e.printStackTrace(); // prints "java.lang.NullPointerException" } }
The output I would like to see is a complete stack table with line numbers and a class hierarchy that did not execute. For instance,
Exception in thread "main" java.lang.NullPointerException at org.Test.myMethod(Test.java:674) at org.TestRunner.anotherMethod(TestRunner.java:505) at java.util.ArrayList(ArrayList.java:405)
This code runs inside a larger application that also has log4j, but I hope to get an exception in the string, so I can send it as an email to java developers.
Does anyone have any ideas on how I can capture a full stack trace into a string? I can not use Thread.currentThread (). GetStackTrace () since this application runs in Java 4. What can block the above code from printing the full stacktrace?
David source share