Java tutorial
//package com.java2s; //License from project: Apache License import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; public class Main { public static String getStackTrace(Throwable aThrowable) { aThrowable.printStackTrace(); final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); aThrowable.printStackTrace(printWriter); return result.toString(); } }