This code snippet gives us Stack flow at any point in java code execuition irrespective of any errors. This oudl be really helpful where we are new to the project and trying to under stand teh work flow. By invoking this method call , it prints the stack trace , thus giving us clarity on the work flow.
public static void showCallStack() { System.out.println(" Call Stack trace...............n***************************START************n"); // Will create stack trace of current thread execution StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); //for looping across the stack trace elements for (int i=2 ; i<stackTraceElements.length; i++) { StackTraceElement ste = stackTraceElements[i]; String classname = ste.getClassName(); String methodName = ste.getMethodName(); int lineNumber = ste.getLineNumber(); System.out.println( classname+"."+methodName+":"+lineNumber); } System.out.println(" Call Stack trace ends ...............n**********************************************nnn"); }