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

StringgetExceptionString(Throwable e)
get Exception String
if (e == null)
    return "";
StringWriter strWriter = new StringWriter();
PrintWriter writer = new PrintWriter(strWriter, true);
e.printStackTrace(writer);
StringBuffer sb = strWriter.getBuffer();
String s = "cause by: \n\t" + sb.toString();
return s.replace("Caused by:", "<font color='red'>Caused by:");
...
StringgetExceptionString(Throwable t)
Returns exception string for class
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
return sw.toString();
StringgetExceptionString(Throwable throwable)
getExceptionString
StringWriter stringWriter = new StringWriter();
throwable.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
StringgetExceptionText(Throwable e)
get Exception Text
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.print(e.toString() + "\n" + e.getMessage() + "\n");
e.printStackTrace(pw);
return sw.toString();
StringgetExceptionTrace(Throwable e)
Get the stack trace of the exception.
if (e != null) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    return sw.toString();
return "No Exception";
StringgetStackTrace(final Throwable e)
get Stack Trace
final Writer sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
StringgetStackTrace(@Nonnull final Throwable throwable)
Yoinked from apache commons 3 because that's what we were using.
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw, true);
throwable.printStackTrace(pw);
return sw.getBuffer().toString();
StringgetStackTrace(final Throwable aThrowable)
get Stack Trace
String errorMsg = aThrowable.getMessage();
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
aThrowable.printStackTrace(printWriter);
return errorMsg + "\n" + result.toString();
StringgetStackTrace(final Throwable e)
Gets the stack trace of exception as string
final StringWriter s = new StringWriter();
e.printStackTrace(new PrintWriter(s));
return s.toString();
StringgetStackTrace(final Throwable error)
Returns error stacktrace as a String.
StringWriter writer = new StringWriter();
for (StackTraceElement element : error.getStackTrace()) {
    writer.write(element.toString());
try {
    return writer.toString();
} finally {
    try {
...