Java Stacktrace Print printStackTraceToString(final Throwable t)

Here you can find the source of printStackTraceToString(final Throwable t)

Description

print Stack Trace To String

License

Apache License

Declaration

public static String printStackTraceToString(final Throwable t) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    public static String printStackTraceToString(final Throwable t) throws IOException {
        try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw);) {
            t.printStackTrace(pw);//from  w w  w  .j av a 2 s. com
            pw.flush();
            sw.flush();
            return sw.toString();
        }
    }
}

Related

  1. printStackTraceAsHtml(Throwable t)
  2. printStackTraceElement(StackTraceElement element, StringBuilder buffer)
  3. printStackTraceHTML(Throwable e)
  4. printStackTraces()
  5. printStackTraceToOutputStream(Throwable t, OutputStream out)
  6. printStackTraceToString(Throwable aThrowable)
  7. printStackTraceUsingStream(Throwable throwable)