Java Stacktrace Print printStackTrace(Throwable t)

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

Description

Print the full stack trace of a Throwable object into a string buffer and return the corresponding string.

License

Open Source License

Declaration

public static String printStackTrace(Throwable t) 

Method Source Code

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

Related

  1. printStackTrace(String msg, Throwable throwable)
  2. printStacktrace(Throwable aException)
  3. printStackTrace(Throwable e)
  4. printStackTrace(Throwable exception)
  5. printStackTrace(Throwable t)
  6. printStackTrace(Throwable t)
  7. printStackTrace(Throwable throwable)
  8. printStackTrace(Throwable throwable)
  9. printStackTraceAsHtml(Throwable t)