Java Utililty Methods Stacktrace Print

List of utility methods to do Stacktrace Print

Description

The list of methods to do Stacktrace Print are organized into topic(s).

Method

StringprintStackTrace(Throwable throwable)
print Stack Trace
StringBuilder sb = new StringBuilder();
sb.append("Caused by: ").append(throwable).append('\n');
for (StackTraceElement ste : throwable.getStackTrace()) {
    sb.append('\t').append(ste.toString()).append('\n');
if (throwable.getCause() != null) {
    return sb.toString() + printStackTrace(throwable.getCause());
} else {
...
voidprintStackTrace(Throwable throwable)
Prints the given stacktrace
if (DEBUG) {
    throwable.printStackTrace();
StringprintStackTraceAsHtml(Throwable t)
Formats a subset of a throwable's stack trace as HTML.
StackTraceElement[] stes = t.getStackTrace();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < stes.length && i <= MAX_STACK_FRAME; i++) {
    sb.append("&nbsp;&nbsp;&nbsp;&nbsp;").append(stes[i].getClassName()).append(":")
            .append(stes[i].getLineNumber()).append(": ").append(stes[i].getMethodName()).append("<br/>");
if (MAX_STACK_FRAME < stes.length - 1) {
    sb.append("&nbsp;&nbsp;&nbsp;&nbsp;...<br/>");
...
voidprintStackTraceElement(StackTraceElement element, StringBuilder buffer)
IMprime un stacktrace element.
buffer.append(element.getClassName());
buffer.append('.');
buffer.append(element.getMethodName());
buffer.append('(');
buffer.append(element.getFileName());
if (element.getLineNumber() > 0) {
    buffer.append(':');
    buffer.append(element.getLineNumber());
...
StringprintStackTraceHTML(Throwable e)
print Stack Trace HTML
final StringBuilder buf = new StringBuilder();
final StackTraceElement[] trace = e.getStackTrace();
buf.append("<table id=\"javatrace\">");
buf.append("<caption>Java Stack Trace:</caption>");
buf.append("<tr><th>Class Name</th><th>Method Name</th><th>File Name</th><th>Line</th></tr>");
for (int i = 0; i < trace.length && i < 20; i++) {
    buf.append("<tr>");
    buf.append("<td class=\"class\">").append(trace[i].getClassName()).append("</td>");
...
voidprintStackTraces()
Print a string representation of the current stack state of all the active threads.
printStackTraces(new PrintWriter(new OutputStreamWriter(System.err)));
voidprintStackTraceToOutputStream(Throwable t, OutputStream out)
print Stack Trace To Output Stream
PrintWriter writer = new PrintWriter(out);
try {
    t.printStackTrace(writer);
} finally {
    writer.flush();
StringprintStackTraceToString(final Throwable t)
print Stack Trace To String
try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw);) {
    t.printStackTrace(pw);
    pw.flush();
    sw.flush();
    return sw.toString();
StringprintStackTraceToString(Throwable aThrowable)
Return a String containing the printed stacktrace of an exception.
StringWriter swriter = new StringWriter();
PrintWriter writer = new PrintWriter(swriter, true);
aThrowable.printStackTrace(writer);
writer.close();
return swriter.toString();
StringprintStackTraceUsingStream(Throwable throwable)
print Stack Trace Using Stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
throwable.printStackTrace(ps);
return baos.toString();