Android examples for java.lang:Throwable
dump the exception to string
//package com.java2s; import java.io.PrintWriter; import java.io.StringWriter; public class Main { /**/*from www. ja va 2s. c om*/ * dump the exception to string */ public static String dumpException(Throwable throwable) { StringWriter stringWriter = new StringWriter(160); stringWriter.write(throwable.getClass().getName()); stringWriter.write(":\n"); throwable.printStackTrace(new PrintWriter(stringWriter)); return stringWriter.toString(); } /** * make throwable to string. */ public static String toString(Throwable throwable) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); printWriter.print(throwable.getClass().getName() + ": "); if (throwable.getMessage() != null) { printWriter.print(throwable.getMessage() + "\n"); } printWriter.println(); try { throwable.printStackTrace(printWriter); return stringWriter.toString(); } finally { printWriter.close(); } } }