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

Discussion in 'Java' started by Mike H, Feb 26, 2004.

  1. Mike H

    Mike H Guest

    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:
    Mike H, Feb 26, 2004
    #1
    1. Advertising

  2. Mike H

    Chris Smith Guest

    Mike H wrote:
    > 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
    Chris Smith, Feb 27, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Hatch
    Replies:
    3
    Views:
    449
    Martin Honnen
    Jun 4, 2006
  2. Replies:
    0
    Views:
    654
  3. Rowland Smith

    chained exceptions

    Rowland Smith, Jun 10, 2008, in forum: Python
    Replies:
    0
    Views:
    287
    Rowland Smith
    Jun 10, 2008
  4. Ivan Fomichev

    Chained exceptions in Perl

    Ivan Fomichev, May 4, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    91
    Ivan Fomichev
    May 4, 2007
  5. Steven D'Aprano

    Awsome Python - chained exceptions

    Steven D'Aprano, Feb 12, 2013, in forum: Python
    Replies:
    41
    Views:
    703
    Dennis Lee Bieber
    Feb 20, 2013
Loading...

Share This Page