Java Stacktrace to String getStackTrace(Exception e)

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

Description

get Stack Trace

License

Open Source License

Declaration

static public String getStackTrace(Exception e) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

public class Main {

    static public String getStackTrace(Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
        e.printStackTrace(ps);// w ww .  j a v a 2  s .  co  m
        ps.flush();
        try {
            return baos.toString("UTF-8");
        } catch (UnsupportedEncodingException ee) {
            return baos.toString();
        }
    }
}

Related

  1. getStackTrace()
  2. getStackTrace()
  3. getStackTrace(Exception e)
  4. getStackTrace(Exception e)
  5. getStackTrace(Exception e)
  6. getStackTrace(Exception exception)
  7. getStackTrace(Exception x)
  8. getStacktraceAsString(Exception e)
  9. getStacktraceAsString(Exception e)