Here you can find the source of stackTraceToString(Throwable t)
Parameter | Description |
---|---|
t | the Throwable to get the stack trace for |
public static final String stackTraceToString(Throwable t)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.io.IOException; import java.io.Reader; public class Main { /**/*from www .j av a 2 s . c o m*/ * Gets a String containing the stack trace for the specified Throwable. * * @param t the Throwable to get the stack trace for * @return the stack trace as a String */ public static final String stackTraceToString(Throwable t) { ByteArrayOutputStream buf = new ByteArrayOutputStream(); PrintStream out = new PrintStream(buf); t.printStackTrace(out); out.flush(); return (buf.toString()); } /** * <p>Reads characters from a Reader and creates a String * from those characters.</p> * * NOTE: This method will terminate the String if a null character * is encountered. * * @param reader the Reader to read characters from * @return the built up String * @throws IOException on any error */ public static String toString(Reader reader) throws IOException { StringBuffer buf = new StringBuffer(1024); while (true) { int c = reader.read(); if (c <= 0) { break; } buf.append(c); } return (buf.toString()); } }