get Stack Trace As String - Java java.lang

Java examples for java.lang:Exception StackTrace

Description

get Stack Trace As String

Demo Code

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

public class Main {
    public static String getStackTraceAsString(Exception e) {

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);/*w w w .j a  va2s.c o m*/
        return sw.toString();

    }
}

Related Tutorials