Java tutorial
//package com.java2s; public class Main { public static String getExceptionStackTrace(Throwable throwable) { if (null == throwable) { return "null"; } StringBuilder sb = new StringBuilder(throwable.getMessage()).append("\n"); StackTraceElement[] elements = throwable.getStackTrace(); for (StackTraceElement element : elements) { sb.append(element.toString()).append("\r\n"); } return sb.toString(); } }