Android Throwable to String Convert exceptionToString(Throwable t)

Here you can find the source of exceptionToString(Throwable t)

Description

exception To String

Declaration

public static String exceptionToString(Throwable t) 

Method Source Code

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

public class Main {

    public static String exceptionToString(Throwable t) {
        if (t == null)
            return null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {//from www .  j av a2  s  .  c  om
            t.printStackTrace(new PrintStream(baos));
        } finally {
            try {
                baos.close();
            } catch (Exception ex) {
                ex.printStackTrace();
                System.gc();
            }
        }
        return baos.toString();
    }
}

Related

  1. stringify(Throwable t)
  2. getExceptionMessage(Throwable e)
  3. getExceptionMessage(Throwable ex)
  4. failException(String message, Throwable got)