Java Stacktrace Print printStackTrace()

Here you can find the source of printStackTrace()

Description

print Stack Trace

License

Open Source License

Declaration

public static void printStackTrace() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void printStackTrace() {
        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
        // Cnt 2 avoids two steps from the stack trace (the getStackTrace itself and the call to this function itself)
        int cnt = 2;
        for (StackTraceElement element : stackTraceElements) {
            if (cnt-- <= 0)
                System.out.println("  " + element.getClassName() + "." + element.getMethodName() + " ("
                        + element.getFileName() + ":" + element.getLineNumber() + ")");
        }/*from w w  w. j a  v  a  2s  .c o  m*/
    }
}

Related

  1. formatStackTraceToString(Exception ex)
  2. printStackTrace()
  3. printStackTrace()
  4. printStackTrace()
  5. printStackTrace()
  6. printStackTrace()
  7. printStackTrace()
  8. printStackTrace()
  9. printStackTrace()