Java examples for java.lang:Exception StackTrace
get Stack Trace and return a String
import java.io.PrintWriter; import java.io.StringWriter; public class Main { public static String getStackTrace(Throwable t) { String stackTrace = null;/*from w ww . j av a2 s .c om*/ try { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); pw.close(); sw.close(); stackTrace = sw.getBuffer().toString(); } catch (Exception ex) { } return stackTrace; } }