Java Throwable to String getStackTraceAsString(Throwable t)

Here you can find the source of getStackTraceAsString(Throwable t)

Description

Prints the Throwable object's stack trace into a string, so that it can be safely printed without the possibility of throwing an exception

License

Open Source License

Declaration

public static String getStackTraceAsString(Throwable t) 

Method Source Code


//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();
    }
}

Related

  1. getStackTraceAsStr(Throwable t)
  2. getStackTraceAsString(Throwable e)
  3. getStackTraceAsString(Throwable ex)
  4. getStackTraceAsString(Throwable ex)
  5. getStackTraceAsString(Throwable t)
  6. getStackTraceAsString(Throwable t)
  7. getStackTraceAsString(Throwable t)
  8. getStackTraceAsString(Throwable throwable)
  9. getStackTraceAsString(Throwable throwable)