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 throwable)

Gets the stack trace from a Throwable as a String.

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
throwable.printStackTrace(pw);
return sw.getBuffer().toString();
StringgetStackTrace(Throwable throwable)
get Stack Trace
if (throwable == null) {
    return "no exception";
} else {
    ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
    PrintWriter printwriter = new PrintWriter(new OutputStreamWriter(bytearrayoutputstream));
    throwable.printStackTrace(printwriter);
    printwriter.flush();
    printwriter.close();
...
StringgetStackTrace(Throwable throwable)
Get the stack trace of the supplied exception.
if (throwable == null)
    return null;
final ByteArrayOutputStream bas = new ByteArrayOutputStream();
final PrintWriter pw = new PrintWriter(bas);
throwable.printStackTrace(pw);
pw.close();
return bas.toString();
StringgetStackTrace(Throwable throwable)
get Stack Trace
if (throwable == null) {
    return "";
StringWriter swrt = new StringWriter();
PrintWriter pwrt = new PrintWriter(swrt);
throwable.printStackTrace(pwrt);
return swrt.toString();
StringgetStackTrace(Throwable thrown)
Takes a throwable and puts it's stacktrace into a string.
try {
    Writer writer = new StringWriter();
    PrintWriter printWriter = new PrintWriter(writer);
    thrown.printStackTrace(printWriter);
    return writer.toString();
} catch (Exception exc) {
    return "";
java.io.ByteArrayOutputStreamgetStackTraceAsByteArrayOutputStream(Throwable throwable)
get Stack Trace As Byte Array Output Stream
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
java.io.PrintWriter pw = new java.io.PrintWriter(baos);
throwable.printStackTrace(pw);
pw.flush();
return baos;
StringgetStackTraceAsStr(Throwable t)
Returns the stack trace of t as a string with each element of the trace separated by a newline character.
StringWriter sw = new StringWriter(2048);
PrintWriter writer = new PrintWriter(sw);
t.printStackTrace(writer);
writer.flush();
return sw.toString();
StringgetStackTraceAsString(Throwable e)
Returns the stack trace of an exception in String form
return getStackTraceAsString(e, false);
StringgetStackTraceAsString(Throwable ex)
Prints the stack trace logonservice a String so it can be put on the normal logs.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream pstr = new PrintStream(baos);
if (ex == null)
    ex = new Exception();
ex.printStackTrace(pstr);
return new String(baos.toByteArray());
StringgetStackTraceAsString(Throwable ex)
get Stack Trace As String
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(bytes, true);
writer.println("<h2>" + ex.getMessage() + "</h2><br/>");
ex.printStackTrace(writer);
while (true) {
    ex = ex.getCause();
    if (ex != null) {
        writer.println("<br/><h2>Caused by: " + ex.getMessage() + "</h2><br/>");
...