Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

RE: How to fill what printStackTrace() output into a String?

frederik de backer

2004-01-13


  /**
  * Returns the output of printStackTrace as a String.
  *
  * @param e A Throwable.
  * @return A String.
  */
  public static final String stackTrace(Throwable e)
  {
    String foo = null;
    try
    {
       // And show the Error Screen.
       ByteArrayOutputStream ostr = new ByteArrayOutputStream();
       e.printStackTrace( new PrintWriter(ostr,true) );
       foo = ostr.toString();
    }
    catch (Exception f)
    {
       // Do nothing.
    }
    return foo;
  }


-----Original Message-----
From: Chris Wahl [mailto:guoqian.wang@(protected)]
Sent: 13 January 2004 14:16
To: Tomcat Users List
Subject: How to fill what printStackTrace() output into a String?


Hi, all

I want to get the exception stack trace and I 'd like to use a
String to contain the info, How can I do?

I am thinking about this: (ex is an instance of Exception )

      PrintStream trace = new PrintStream();
      ex.printStackTrace(trace);
      String str = doSomeThing (trace);

Then how to write the function doSomeThing() ?

Is there any elegance solution?

TIA
Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)



©2008 junlu.com - Jax Systems, LLC, U.S.A.