Java Throwable to String getStackTrace(Throwable e)

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

Description

get Stack Trace

License

Open Source License

Declaration

public static String getStackTrace(Throwable e) 

Method Source Code


//package com.java2s;
import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    public static String getStackTrace(Throwable e) {
        StringWriter out = new StringWriter();
        PrintWriter w = new PrintWriter(out);
        e.printStackTrace(w);/*from   w w w .  j  av  a  2  s  . com*/
        w.flush();
        return out.toString();
    }

    public static String getStackTrace(Throwable e, int endIndex) {
        String stackTrace = getStackTrace(e);
        if (stackTrace != null && stackTrace.length() > endIndex) {
            stackTrace = stackTrace.substring(0, endIndex) + "...";
        }
        return stackTrace;
    }
}

Related

  1. getStackTrace(final Throwable t)
  2. getStackTrace(final Throwable t)
  3. getStackTrace(final Throwable throwable)
  4. getStackTrace(Throwable aThrowable)
  5. getStackTrace(Throwable aThrowable)
  6. getStackTrace(Throwable e)
  7. getStackTrace(Throwable e)
  8. getStackTrace(Throwable ex)
  9. getStackTrace(Throwable ex)