M
Mike H
I want to get the complete stack trace output and don't care about
excessive output. I've run into some cases where chained exceptions
are abbreviated (ex. "... 58 more") too much so it is hard to track
down what really happened. Is there a way to easily prevent the stack
trace output from being abbreviated? I wrote a bit of code to get the
complete trace, but I'd like to avoid using it if there is a built in
facility or flag I can use:
Throwable cause = originalException.getCause();
while(cause != null){
StackTraceElement[] trace = cause.getStackTrace();
System.out.println("Caused by:");
for(int i=0;i<trace.length;i++) {
System.out.println(" " + trace.getClassName() + "."
+ trace.getMethodName() + "(" + trace.getFileName()
+ ":" + trace.getLineNumber() + ")");
}
cause = cause.getCause();
}
Background
From the Sun javadoc on Throwable.printStackTrace():
Note the presence of lines containing the characters "...". These
lines indicate that the remainder of the stack trace for this
exception matches the indicated number of frames from the bottom of
the stack trace of the exception that was caused by this exception
(the "enclosing" exception). This shorthand can greatly reduce the
length of the output in the common case where a wrapped exception is
thrown from same method as the "causative exception" is caught. The
above example was produced by running the program:
excessive output. I've run into some cases where chained exceptions
are abbreviated (ex. "... 58 more") too much so it is hard to track
down what really happened. Is there a way to easily prevent the stack
trace output from being abbreviated? I wrote a bit of code to get the
complete trace, but I'd like to avoid using it if there is a built in
facility or flag I can use:
Throwable cause = originalException.getCause();
while(cause != null){
StackTraceElement[] trace = cause.getStackTrace();
System.out.println("Caused by:");
for(int i=0;i<trace.length;i++) {
System.out.println(" " + trace.getClassName() + "."
+ trace.getMethodName() + "(" + trace.getFileName()
+ ":" + trace.getLineNumber() + ")");
}
cause = cause.getCause();
}
Background
From the Sun javadoc on Throwable.printStackTrace():
Note the presence of lines containing the characters "...". These
lines indicate that the remainder of the stack trace for this
exception matches the indicated number of frames from the bottom of
the stack trace of the exception that was caused by this exception
(the "enclosing" exception). This shorthand can greatly reduce the
length of the output in the common case where a wrapped exception is
thrown from same method as the "causative exception" is caught. The
above example was produced by running the program: