Takes stacktrace string out of exception. - Java java.lang

Java examples for java.lang:Exception

Description

Takes stacktrace string out of exception.

Demo Code

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
//package com.java2s;
import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    /**//from w w  w.j a  v  a  2s.co  m
     * Takes stacktrace string out of exception.
     */
    public static String getStacktraceString(Exception exception) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        exception.printStackTrace(printWriter);
        printWriter.close();
        return stringWriter.toString();
    }
}

Related Tutorials