Java Utililty Methods Throwable to String

List of utility methods to do Throwable to String

Description

The list of methods to do Throwable to String are organized into topic(s).

Method

StringstackTrace(final Throwable t)
Return the stack trace for the given throwable as a string.
final ByteArrayOutputStream out = new ByteArrayOutputStream();
getRootException(t).printStackTrace(new PrintWriter(out, true));
return out.toString();
voidstacktrace(Logger logger, Throwable ex)
Print the stacktrace for the exception in the logfile.
if (logger.isDebugEnabled()) {
    logger.debug("*******************************************************************");
    logger.debug(ex.getLocalizedMessage());
    StackTraceElement[] ste = ex.getStackTrace();
    if (ste != null && ste.length > 0) {
        for (StackTraceElement st : ste) {
            logger.debug(st.getClassName() + "." + st.getMethodName() + "() [" + st.getFileName() + ":"
                    + st.getLineNumber() + "]");
...
StringstackTrace(Throwable cause)
stack Trace
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
PrintStream printStream = new PrintStream(bufferedOutputStream);
cause.printStackTrace(printStream);
printStream.flush();
return byteArrayOutputStream.toString();
StringstackTrace(Throwable e)
stack Trace
try {
    ByteArrayOutputStream trace = new ByteArrayOutputStream();
    PrintStream dump = new PrintStream(trace, true, "utf8");
    e.printStackTrace(dump);
    return trace.toString("utf8");
} catch (Exception shouldNotHappen) {
    throw new RuntimeException(shouldNotHappen);
StringstackTrace(Throwable e)
Returns the output of printStackTrace as a String.
String throwableAsString = null;
try {
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    e.printStackTrace(new PrintWriter(buf, true));
    throwableAsString = buf.toString();
} catch (Exception f) {
return throwableAsString;
...
StringstackTrace(Throwable e)
stack Trace
StringWriter buf = new StringWriter();
e.printStackTrace(new PrintWriter(buf));
return buf.toString();
StringstackTrace(Throwable e)
Returns a string containing the representation of the stack trace of the exception
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
e.printStackTrace(pw);
pw.flush();
sw.flush();
return sw.toString();
StringstackTrace(Throwable exception)
Returns the stack trace of an Throwable as a String.
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);
exception.printStackTrace(printStream);
return outputStream.toString();
StringstackTrace(Throwable t)
stack Trace
StringWriter sw = new StringWriter(0);
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
pw.close();
return sw.getBuffer().toString();
StringstackTrace(Throwable t)
stack Trace
String s = null;
try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    t.printStackTrace(new PrintWriter(baos, true));
    s = baos.toString();
} catch (Exception e) {
return s;
...