Can abbreviated printStackTrace() output be easily prevented for chained exceptions?

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:
 
C

Chris Smith

Mike said:
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:

Nope, I don't see such a mechanism. If you need your own format for the
stack trace, you'll have to produce it manually rather than rely on
printStackTrace, just as you've done.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,192
Latest member
KalaReid2

Latest Threads

Top