/**
     * 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:[EMAIL 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to