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

StringgetStackTrace(Throwable t)
Returns a stack trace as a string.
StringWriter out = new StringWriter();
PrintWriter writer = new PrintWriter(out);
t.printStackTrace(writer);
return out.toString();
StringgetStackTrace(Throwable t)
Returns a string representation of the stack trace of a Throwable
StringWriter sw = new StringWriter(1024);
PrintWriter pw = null;
try {
    pw = new PrintWriter(sw);
    t.printStackTrace(pw);
    pw.close();
} catch (Exception ignored) {
return sw.toString();
StringgetStackTrace(Throwable t)
get Stack Trace
if (t != null) {
    StringWriter stringWritter = new StringWriter();
    PrintWriter printWritter = new PrintWriter(stringWritter, true);
    t.printStackTrace(printWritter);
    printWritter.flush();
    stringWritter.flush();
    return stringWritter.toString();
return "";
StringgetStackTrace(Throwable t)
Returns a string representation of the stack trace for a Throwable object.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
t.printStackTrace(pw);
pw.flush();
sw.flush();
String trace = sw.toString();
int traceLength = trace.length();
if (traceLength >= 1200)
...
StringgetStackTrace(Throwable t)
get Stack Trace
Throwable cur = t;
String stacktrace = "--- Exception Details ---\r\n";
while (cur != null) {
    StringWriter sw = new StringWriter();
    t.printStackTrace(new PrintWriter(sw));
    stacktrace += t.getMessage() + "\r\n" + sw.toString();
    cur = t.getCause();
    if (cur != null) {
...
StringgetStackTrace(Throwable t)
get Stack Trace
String stackTrace = null;
PrintWriter printWriter = null;
try {
    StringWriter stringWriter = new StringWriter();
    printWriter = new PrintWriter(new BufferedWriter(stringWriter));
    t.printStackTrace(printWriter);
    printWriter.flush();
    stackTrace = stringWriter.toString();
...
StringgetStackTrace(Throwable t0)
Gets stack trace.
if (null == t0) {
    return "";
StringWriter sw = new StringWriter();
t0.printStackTrace(new PrintWriter(sw));
return sw.toString();
StringgetStackTrace(Throwable tException)
This method returns the string-representation of the stacktrace of the passed on exception.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
tException.printStackTrace(pw);
pw.flush();
return sw.getBuffer().toString();
StringgetStackTrace(Throwable th)
get Stack Trace
if (th == null) {
    throw new IllegalArgumentException("Throwable is null");
StringWriter sw = new StringWriter();
try {
    PrintWriter pw = new PrintWriter(sw);
    try {
        th.printStackTrace(pw);
...
StringgetStackTrace(Throwable throwable)
get Stack Trace
StringWriter stringWriter = new StringWriter();
throwable.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();