Here you can find the source of printStackTrace()
public static void printStackTrace()
//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*/ } }