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;
//License from project: Open Source License 

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

public class Main {
    public static String getStackTrace(Throwable t) {

        Throwable cur = t;/*  www.  j  ava  2  s .  c  o m*/
        String stacktrace = "--- Exception Details ---\r\n";
        while (cur != null) {
            StringWriter sw = new StringWriter();
            t.printStackTrace(new PrintWriter(sw));
            stacktrace += t.getMessage() + "\r\n" + sw.toString();

            cur = t.getCause();
            if (cur != null) {
                stacktrace += "\r\n-- Caused by -- \r\n";
            }
        }

        return stacktrace;
    }
}

Related

  1. getStackTrace(Throwable t)
  2. getStackTrace(Throwable t)
  3. getStackTrace(Throwable t)
  4. getStackTrace(Throwable t)
  5. getStackTrace(Throwable t)
  6. getStackTrace(Throwable t)
  7. getStackTrace(Throwable t0)
  8. getStackTrace(Throwable tException)
  9. getStackTrace(Throwable th)