Get exception call stack information - Java java.lang

Java examples for java.lang:Throwable

Description

Get exception call stack information

Demo Code


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

public class Main {
    /**/*from w ww  . j a  v a  2 s .c o  m*/
     * Get exception call stack information
     * 
     * @param e
     * @return
     */
    public static String exception(Exception e) {
        StringWriter writer = new StringWriter();
        String rvalue = "";

        try {
            e.printStackTrace(new PrintWriter(writer));
            rvalue = writer.toString();
            return rvalue.substring(0, rvalue.length() - 1);
        } catch (Exception ex) {
            // ignore
        }

        return rvalue;
    }
}

Related Tutorials