Here you can find the source of getStackTrace(Throwable ex)
public static String getStackTrace(Throwable ex)
//package com.java2s; /*//from w w w .j a v a 2 s . c om * Copyright (c) 2006-2010 Marvisan Pty. Ltd. All rights reserved.6 * Use is subject to license terms. */ import java.io.PrintWriter; import java.io.StringWriter; public class Main { public static String getStackTrace(Throwable ex) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); pw.write("\n---------------------- EXCEPTION STACK TRACE ----------------------\n"); ex.printStackTrace(pw); if (ex.getCause() != null) { pw.write("\n---------------------- CAUSE EXCEPTION STACK TRACE ----------------------\n"); ex.getCause().printStackTrace(pw); pw.write("\n---------------------- CAUSE EXCEPTION STACK TRACE ----------------------\n"); } pw.write("\n---------------------- EXCEPTION STACK TRACE ----------------------\n"); pw.flush(); sw.flush(); return sw.toString(); } }