Here you can find the source of getStackTraceAsString(Throwable t)
public static String getStackTraceAsString(Throwable t)
//package com.java2s; /*/*from www . j a v a 2 s . com*/ * StringUtil.java * * This file is part of the IHMC Util Library * Copyright (c) 1993-2016 IHMC. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 3 (GPLv3) as published by the Free Software Foundation. * * U.S. Government agencies and organizations may redistribute * and/or modify this program under terms equivalent to * "Government Purpose Rights" as defined by DFARS * 252.227-7014(a)(12) (February 2014). * * Alternative licenses that allow for use within commercial products may be * available. Contact Niranjan Suri at IHMC (nsuri@ihmc.us) for details. */ import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; public class Main { /** * Prints the Throwable object's stack trace into a string, so that it can * be safely printed without the possibility of throwing an exception * * @author Giacomo Benincasa <gbenincasa@ihmc.us> */ public static String getStackTraceAsString(Throwable t) { final Writer sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); return sw.toString(); } }