Here you can find the source of printStackTrace(Throwable t)
Print the full stack trace of a Throwable
object into a string buffer and return the corresponding string.
public static String printStackTrace(Throwable t)
//package com.java2s; /* /*from w w w.ja v a 2 s. co m*/ * This file is part of the HyperGraphDB source distribution. This is copyrighted * software. For permitted uses, licensing options and redistribution, please see * the LicensingInformation file at the root level of the distribution. * * Copyright (c) 2005-2010 Kobrix Software, Inc. All rights reserved. */ import java.io.PrintStream; public class Main { /** * <p> * Print the full stack trace of a <code>Throwable</code> object into a * string buffer and return the corresponding string. * </p> */ public static String printStackTrace(Throwable t) { java.io.StringWriter strWriter = new java.io.StringWriter(); java.io.PrintWriter prWriter = new java.io.PrintWriter(strWriter); t.printStackTrace(prWriter); prWriter.flush(); return strWriter.toString(); } public static void printStackTrace(StackTraceElement[] trace, PrintStream out) { for (StackTraceElement el : trace) out.println(el.toString()); } }