Java tutorial
//package com.java2s; import java.io.PrintWriter; import java.io.StringWriter; public class Main { public static String getStackTraceString(Throwable t) { String value; if (t == null) { value = ""; } else { final StringWriter stackTrace = new StringWriter(); t.printStackTrace(new PrintWriter(stackTrace)); value = stackTrace.toString(); } return value; } }