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(StackTraceElement[] stes, String filter)
print Stack Trace
StringBuilder sb = new StringBuilder();
for (StackTraceElement ste : stes) {
    if (filter == null || ste.getClassName().startsWith(filter)) {
        sb.append("\n\t").append("at ").append(ste.getClassName()).append(" (").append(ste.getFileName())
                .append(":").append(ste.getLineNumber()).append(")");
return sb.toString();
...
voidprintStackTrace(String header, int depth)
print Stack Trace
System.out.println(header);
int i = 0;
for (StackTraceElement se : Thread.currentThread().getStackTrace()) {
    System.out.println(se);
    if (i++ > depth) {
        break;
voidprintStackTrace(String msg, StackTraceElement[] trace, PrintStream out)
Print given message, stack trace to the underlying print stream
Exception ex = new Exception(msg);
ex.setStackTrace(trace);
ex.printStackTrace(out);
voidprintStackTrace(String msg, Throwable throwable)
print Stack Trace
StringBuilder str = new StringBuilder(
        throwable.getClass().getName() + " : " + throwable.getMessage() + "(" + msg + ")\n");
str.append(stackTrace(throwable.getStackTrace()));
System.err.println(str.toString());
Throwable cause = throwable.getCause();
if (cause != null) {
    printStackTrace(cause.getMessage(), cause);
StringprintStacktrace(Throwable aException)
Dump a stack trace to a string
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(bout);
aException.printStackTrace(pw);
pw.flush();
return new String(bout.toByteArray());
StringprintStackTrace(Throwable e)
print Stack Trace
StringWriter stm = new StringWriter();
PrintWriter wrt = new PrintWriter(stm);
e.printStackTrace(wrt);
wrt.close();
return stm.toString();
StringprintStackTrace(Throwable exception)
print Stack Trace
if (exception == null) {
    return "";
} else {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    exception.printStackTrace(pw);
    pw.flush();
    String expString = sw.toString();
...
StringprintStackTrace(Throwable t)
Use with caution: lots of overhead
StringWriter s = new StringWriter();
PrintWriter p = new PrintWriter(s);
t.printStackTrace(p);
return s.toString();
StringprintStackTrace(Throwable t)
print Stack Trace
StringWriter strWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(strWriter);
if (t != null) {
    t.printStackTrace(printWriter);
return strWriter.getBuffer().toString();
StringprintStackTrace(Throwable t)

Print the full stack trace of a Throwable object into a string buffer and return the corresponding string.

java.io.StringWriter strWriter = new java.io.StringWriter();
java.io.PrintWriter prWriter = new java.io.PrintWriter(strWriter);
t.printStackTrace(prWriter);
prWriter.flush();
return strWriter.toString();