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

StringstackTraceFromThrowable(Throwable throwable)
stack Trace From Throwable
StringWriter stringWriter = new StringWriter();
throwable.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
StringstackTraceOf(Throwable e)
stack Trace Of
ByteArrayOutputStream output = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(output));
return output.toString();
StringstackTraceString(final Throwable exception)
stack Trace String
ByteArrayOutputStream bao = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(bao);
exception.printStackTrace(printStream);
String stackTraceString = bao.toString();
return stackTraceString;
CharSequencestackTraceToCharSequence(final Throwable error)
stack Trace To Char Sequence
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
error.printStackTrace(pw);
pw.flush();
return sw.getBuffer();
StringstackTraceToHTMLString(Throwable t)
stack Trace To HTML String
return stackTraceToHTMLString(t, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", "<br>");
StringstackTraceToString(final Throwable t)
Convert a stack trace of an exception into a string.
if (t == null) {
    return null;
final StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
return sw.toString();
StringstackTraceToString(final Throwable thr)
stack Trace To String
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
thr.printStackTrace(new PrintStream(baos));
return baos.toString();
StringstackTraceToString(final Throwable throwable, final boolean expectNull)
Returns a stack trace of the Throwable as a String .
if (throwable == null) {
    if (expectNull == true) {
        return null;
    return "";
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
...
StringstackTraceToString(Throwable cause)

Gets the stack trace from a Throwable as a String.

ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream pout = new PrintStream(out);
cause.printStackTrace(pout);
pout.flush();
try {
    return new String(out.toByteArray());
} finally {
    try {
...
StringstackTraceToString(Throwable cause)
stack Trace To String
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream pout = new PrintStream(out);
cause.printStackTrace(pout);
pout.flush();
try {
    return new String(out.toByteArray());
} finally {
    try {
...