Java Throwable to String getStackTrace(Throwable throwable)

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

Description

get Stack Trace

License

Apache License

Declaration

public static String getStackTrace(Throwable throwable) 

Method Source Code

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

import java.io.ByteArrayOutputStream;

import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
    public static String getStackTrace(Throwable throwable) {
        if (throwable == null) {
            return "no exception";
        } else {//from   w  ww  . j  av a2s .co m
            ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
            PrintWriter printwriter = new PrintWriter(new OutputStreamWriter(bytearrayoutputstream));
            throwable.printStackTrace(printwriter);
            printwriter.flush();
            printwriter.close();
            return bytearrayoutputstream.toString();
        }
    }
}

Related

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