Java Stacktrace to String getStackTraceStr(Exception e)

Here you can find the source of getStackTraceStr(Exception e)

Description

get Stack Trace Str

License

Open Source License

Declaration

public static String getStackTraceStr(Exception e) 

Method Source Code


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

public class Main {

    public static String getStackTraceStr(Exception e) {
        StringWriter sw = null;//from  w  ww  . j a  v  a 2 s.com
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
        } finally {
            if (sw != null) {
                try {
                    sw.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (pw != null) {
                pw.close();
            }
        }
        return sw.toString();
    }
}

Related

  1. getStackTraceAsString(Exception e)
  2. getStackTraceAsString(String pstrMessage, Exception poException)
  3. getStackTraceFromException(Exception _e)
  4. getStackTraceFromException(Exception e)
  5. getStackTraces()
  6. getStackTraceString()
  7. getStackTraceString(Exception e)
  8. getStackTraceString(Exception e)
  9. stackTrace()