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

StringformatException(Throwable e)
Formats an exception as a string for logging purposes

Necessary because slf4j does not by default have a method for logging exceptions

StringWriter writer = new StringWriter();
PrintWriter pwriter = new PrintWriter(writer);
writer.append(e.getClass().getCanonicalName());
if (e.getMessage() != null) {
    writer.append(": ");
    writer.append(e.getMessage());
writer.append('\n');
...
StringformatException(Throwable t)
format Exception
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream s = new PrintStream(baos);
t.printStackTrace(s);
return baos.toString();
StringformatException(Throwable t)
Formats the given Throwable 's stack trace to a string
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
t.printStackTrace(writer);
return stringWriter.toString();
StringformatExceptionForDisplay(Exception e)
format Exception For Display
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
return "<span style=\"color: red;\">An error occurred while searching for Mediasite content. Please contact your Blackboard administrator for more information.</span><!--<pre>"
        + sw.toString() + "</pre>-->";
StringformatThrowableForHtml(Throwable t)
format Throwable For Html
String ex = formatThrowable(t);
return ex.replaceAll("\n\t", " ");
CharSequenceformatThrown(final Throwable thrown)
format Thrown
if (thrown == null)
    return null;
final StringBuilder buffer = new StringBuilder();
formatThrown(thrown, buffer);
return buffer;
StringgetDetails(Throwable t)
Returns a detailed message of the t, including the stack trace.
assert t != null;
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
return t.getMessage() + "\n" + sw.toString();
StringgetErrorInfo(Throwable error)
get Error Info
try {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    error.printStackTrace(pw);
    return sw.toString();
} catch (Exception e1) {
    return "";
StringgetErrorMessage(Throwable e)
get Error Message
Writer writer = new StringWriter();
PrintWriter pWriter = new PrintWriter(writer);
e.printStackTrace(pWriter);
return writer.toString();
StringgetExceptionAsString(Throwable _ex)
get Exception As String
if (_ex == null) {
    return null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (_ex.getStackTrace() == null) {
    _ex.fillInStackTrace();
_ex.printStackTrace(new PrintStream(baos));
...