Java Throwable to String getStackTraceString(Throwable tr)

Here you can find the source of getStackTraceString(Throwable tr)

Description

get Stack Trace String

License

Apache License

Declaration

public static String getStackTraceString(Throwable tr) 

Method Source Code


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

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

public class Main {
    public static String getStackTraceString(Throwable tr) {
        if (tr == null) {
            return "";
        }//from   www  .j  a  v  a2s.  c  o m
        Throwable t = tr;
        while (t.getCause() != null) {
            t = t.getCause();
        }
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        pw.flush();
        return sw.toString();
    }
}

Related

  1. getStackTraceString(Throwable cause, String delimiter, int maxLines)
  2. getStackTraceString(Throwable e)
  3. getStackTraceString(Throwable t)
  4. getStackTraceString(Throwable throwable)
  5. getStackTraceString(Throwable throwable)
  6. getStackTraceWithoutCause(Throwable throwable)
  7. printStackTrace(Throwable t)
  8. serialize(Throwable t)
  9. serializeStackTrace(Throwable _t)