Java Throwable to String stackTraceToString(Throwable th)

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

Description

stack Trace To String

License

BSD License

Declaration

public static final String stackTraceToString(Throwable th) 

Method Source Code


//package com.java2s;
/*//  ww w. j ava 2 s .c  o m
 * Copyright (c) 2008-2011 by Jan Stender, Bjoern Kolbeck,
 *               Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class Main {
    public static final String stackTraceToString(Throwable th) {

        PrintStream ps = null;
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ps = new PrintStream(out);
            if (th != null)
                th.printStackTrace(ps);

            return new String(out.toByteArray());

        } finally {
            if (ps != null)
                ps.close();
        }

    }
}

Related

  1. stacktraceToString(Throwable t)
  2. stackTraceToString(Throwable t)
  3. stackTraceToString(Throwable t)
  4. stackTraceToString(Throwable t)
  5. stackTraceToString(Throwable t)
  6. stackTraceToString(Throwable throwable)