How to know the calling stack trace with just SOP without debugging through IDE

While debugging through the code without IDE , if you want to get the call hierarchy of any particular method to see the flow of the calling methods, adding the following piece of code in the method you are interested in can help you.

StringWriter sw = new StringWriter();
new Throwable(“”).printStackTrace(new PrintWriter(sw));
String stackTrace = sw.toString();
System.out.println(stackTrace);

Leave a comment