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)
get Stack Trace
ByteArrayOutputStream bao = new ByteArrayOutputStream(1024);
PrintWriter pr = new PrintWriter(bao);
t.printStackTrace(pr);
return bao.toString();
StringgetStackTrace(Throwable t)
get Stack Trace
if (t != null) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    t.printStackTrace(printWriter);
    return stringWriter.toString();
return "";
StringgetStackTrace(Throwable t)
get Stack Trace
if (t == null) {
    try {
        throw new Exception();
    } catch (Exception e) {
        t = e;
StringWriter sw = new StringWriter();
...
StringgetStackTrace(Throwable t)
Convenient method to retrieve the full stacktrace from a given exception.
StringWriter sw = null;
PrintWriter pw = null;
try {
    sw = new StringWriter();
    pw = new PrintWriter(sw, true);
    t.printStackTrace(pw);
    pw.flush();
    pw.close();
...
StringgetStackTrace(Throwable t)
get Stack Trace
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
try {
    printWriter.write(t.getMessage());
    printWriter.write("\n");
    t.printStackTrace(printWriter);
} finally {
    close(printWriter);
...
StringgetStackTrace(Throwable t)
get Stack Trace
StringWriter stringWriter = new StringWriter();
t.printStackTrace(new PrintWriter(stringWriter));
String ret = stringWriter.toString();
try {
    stringWriter.close();
} catch (IOException e) {
return ret;
...
StringgetStackTrace(Throwable t)
Returns a String containing the stack trace for a throwable.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
t.printStackTrace(ps);
ps.flush();
String result = baos.toString();
ps.close();
return result;
StringgetStackTrace(Throwable t)
Convenience method for getting a stack trace as a string.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
pw.flush();
pw.close();
return sw.toString();
StringgetStackTrace(Throwable t)
get Stack Trace
ByteArrayOutputStream captureStream;
PrintWriter p;
captureStream = new ByteArrayOutputStream();
p = new PrintWriter(captureStream);
t.printStackTrace(p);
p.flush();
return captureStream.toString();
StringgetStackTrace(Throwable t)
Return the full stack trace for a Throwable.
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
t.printStackTrace(printWriter);
return stringWriter.toString();