Java Throwable to String getStackTrace(final Throwable t)

Here you can find the source of getStackTrace(final Throwable t)

Description

Extracts the given exception's corresponding stack trace to a string.

License

Open Source License

Declaration

public static String getStackTrace(final Throwable t) 

Method Source Code


//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;

public class Main {
    /** Extracts the given exception's corresponding stack trace to a string. */
    public static String getStackTrace(final Throwable t) {
        try {//from ww  w  .j a v a2s . c om
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            t.printStackTrace(new PrintStream(out, false, "UTF-8"));
            return new String(out.toByteArray(), "UTF-8");
        } catch (final IOException exc) {
            return null;
        }
    }
}

Related

  1. getStackTrace(final Throwable e)
  2. getStackTrace(final Throwable error)
  3. getStackTrace(final Throwable exception)
  4. getStackTrace(final Throwable t)
  5. getStackTrace(final Throwable t)
  6. getStackTrace(final Throwable t)
  7. getStackTrace(final Throwable throwable)
  8. getStackTrace(Throwable aThrowable)
  9. getStackTrace(Throwable aThrowable)