KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > debug > StackTraceUtil


1 package com.knowgate.debug;
2
3 import java.io.Writer JavaDoc;
4 import java.io.StringWriter JavaDoc;
5 import java.io.PrintWriter JavaDoc;
6 import java.io.IOException JavaDoc;
7
8 /**
9  * Simple utility to return the stack trace of an exception as a String.
10  * @author John O'Hanley
11  * @version 1.0
12 */

13 public final class StackTraceUtil {
14
15   public static String JavaDoc getStackTrace( Throwable JavaDoc aThrowable )
16     throws IOException JavaDoc {
17     final Writer JavaDoc result = new StringWriter JavaDoc();
18     final PrintWriter JavaDoc printWriter = new PrintWriter JavaDoc( result );
19     aThrowable.printStackTrace( printWriter );
20     String JavaDoc sRetVal = result.toString();
21     printWriter.close();
22     result.close();
23     return sRetVal;
24   }
25 }
26
Popular Tags