Java tutorial
//package com.java2s; import java.io.PrintWriter; import java.io.StringWriter; public class Main { /** * Converts an exception to a string. * @param exception * @return */ public static String getExceptionStackTraceAsString(Exception exception) { StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); return sw.toString(); } }