Java Throwable to String stackTraceToString(Throwable throwable)

Here you can find the source of stackTraceToString(Throwable throwable)

Description

Retrieve the stack trace from the given Throwable, and output the string.

License

Open Source License

Parameter

Parameter Description
throwable Throwable to process.

Return

String output of the thorwable's stack trace.

Declaration

public static String stackTraceToString(Throwable throwable) 

Method Source Code


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

import java.io.PrintWriter;
import java.io.StringWriter;

import java.io.Writer;

public class Main {
    /**//from w  ww  .  j  a v a2  s  .  c om
     * Retrieve the stack trace from the given Throwable, and output the string.
     *
     * @param throwable Throwable to process.
     * @return String output of the thorwable's stack trace.
     */
    public static String stackTraceToString(Throwable throwable) {
        final Writer result = new StringWriter();
        final PrintWriter printWriter = new PrintWriter(result);

        throwable.printStackTrace(printWriter);

        return result.toString();
    }
}

Related

  1. stackTraceToString(Throwable t)
  2. stackTraceToString(Throwable t)
  3. stackTraceToString(Throwable t)
  4. stackTraceToString(Throwable t)
  5. stackTraceToString(Throwable th)