Java Stacktrace Print printStackTrace(String msg, Throwable throwable)

Here you can find the source of printStackTrace(String msg, Throwable throwable)

Description

print Stack Trace

License

Apache License

Declaration

public static void printStackTrace(String msg, Throwable throwable) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static void printStackTrace(String msg, Throwable throwable) {
        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);
        }//from  w  w w  . j a v  a 2  s  .co  m
    }

    public static void printStackTrace(String msg, StackTraceElement[] stackTrace) {
        StringBuilder str = new StringBuilder(msg + "\n");
        str.append(stackTrace(stackTrace));
        System.err.println(str.toString());
        str = null;
    }

    public static void printStackTrace(String msg) {
        System.err.println(msg);
    }

    public static String stackTrace(StackTraceElement[] stackTrace) {
        StringBuilder str = new StringBuilder("");
        for (StackTraceElement s : stackTrace) {
            str.append("\t").append(s.getClassName() + "." + s.getMethodName() + "(" + s.getFileName() + ":"
                    + s.getLineNumber() + ")" + "\n");
        }
        return str.toString();
    }

    public static String stackTrace(String msg, Throwable throwable) {
        StringBuilder str = new StringBuilder(throwable.getMessage() + " : " + msg + "\n");
        str.append(stackTrace(throwable.getStackTrace()));
        return str.toString();
    }
}

Related

  1. printStackTrace(StackTraceElement[] elements)
  2. printStackTrace(StackTraceElement[] stackTrace)
  3. printStackTrace(StackTraceElement[] stes, String filter)
  4. printStackTrace(String header, int depth)
  5. printStackTrace(String msg, StackTraceElement[] trace, PrintStream out)
  6. printStacktrace(Throwable aException)
  7. printStackTrace(Throwable e)
  8. printStackTrace(Throwable exception)
  9. printStackTrace(Throwable t)