Java Throwable to String getStackTrace(Throwable t)

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

Description

get Stack Trace

License

Open Source License

Declaration

public static String getStackTrace(Throwable t) 

Method Source Code


//package com.java2s;

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

public class Main {
    public static String getStackTrace(Throwable t) {
        if (t != null) {
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            t.printStackTrace(printWriter);
            return stringWriter.toString();
        }/*w w  w.j a va2 s .c o m*/
        return "";
    }

    public static String getStackTrace(Thread thread) {
        StringBuffer sb = new StringBuffer();
        StackTraceElement[] trace = thread.getStackTrace();
        for (int i = 0; i < trace.length; i++)
            sb.append("\tat " + trace[i] + "\r\n");
        return sb.toString();

    }
}

Related

  1. getStackTrace(Throwable exception)
  2. getStackTrace(Throwable pException)
  3. getStackTrace(Throwable pThrowable_)
  4. getStackTrace(Throwable t)
  5. getStackTrace(Throwable t)
  6. getStackTrace(Throwable t)
  7. getStackTrace(Throwable t)
  8. getStackTrace(Throwable t)
  9. getStackTrace(Throwable t)