Java tutorial
//package com.java2s; //License from project: Apache License import java.io.PrintWriter; import java.io.StringWriter; public class Main { /** * get stack trace as string * * @param traceElements * - stack trace elements * @return built string */ public static String getStackTrace(Throwable throwable) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); String string = sw.toString(); return string; } }