Java tutorial
//package com.java2s; import java.io.PrintWriter; import java.io.StringWriter; public class Main { /** * get stack trace message * * @param e the Exception * @return stack trace message of the Exception */ public static String getStrackTrace(Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw, true)); String str = sw.toString(); return str; } }