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

voidprintStackTrace()
print Stack Trace
printStackTrace(Thread.currentThread());
StringprintStackTrace(Exception e)
print Stack Trace
StringBuilder str = new StringBuilder();
str.append(e + "\r\n");
str.append("-----------------------------------------\r\n");
StackTraceElement[] trace = e.getStackTrace();
for (int i = 0; i < trace.length; i++) {
    if (trace[i].getLineNumber() == -1)
        continue;
    str.append(trace[i] + "\r\n");
...
voidprintStackTrace(Exception e)
print Stack Trace
if (e != null) {
    System.err.print(e.getClass().getName() + "::");
    System.err
            .println((e.getMessage() == null || e.getMessage().equals("")) ? e.toString() : e.getMessage());
    StackTraceElement[] elements = e.getStackTrace();
    for (int i = 0; i < elements.length; i++) {
        StackTraceElement element = elements[i];
        System.err.println("    - (at " + element.getClassName() + ":" + element.getLineNumber() + ")");
...
StringprintStackTrace(Exception e)
print Stack Trace
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
return sw.toString();
voidprintStackTrace(Exception e)
print Stack Trace
if (e == null)
    print(getStackTrace());
else
    print(stackTraceToString(e.getStackTrace()));
StringprintStackTrace(Exception exception)
Prints the stack trace to a string.
try {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    exception.printStackTrace(printWriter);
    return "M: " + exception.getMessage() + " S: " + stringWriter.toString();
} catch (Exception except) {
    return "Error in printStackTrace: " + except.getMessage();
voidprintStackTrace(final Exception exception)
Synchronized method to ensure message and stack trace are listed consecutively on console.
System.out.println("\tA TestUtil runtime exception [" + exception.getMessage() + "] occured.");
exception.printStackTrace();
voidprintStackTrace(final StackTraceElement[] stack)
print Stack Trace
printStackTrace(stack, System.out); 
voidprintStackTrace(IOException ioe)
print Stack Trace
if (false) {
    ioe.printStackTrace();
voidprintStackTrace(PrintStream out)
This is for debugging use only - prints a snapshot of the current stack trace to the given PrintStream .
try {
    throw new RuntimeException();
} catch (RuntimeException dummy) {
    StackTraceElement[] stack = dummy.getStackTrace();
    out.println("CURRENT STACK SNAPSHOT (depth=" + stack.length + " frames)");
    for (int i = 1; i < stack.length; i++) {
        out.println(" -> method " + stack[i - 1].getMethodName() + " in " + stack[i].getFileName()
                + ", line " + stack[i].getLineNumber());
...