Browse - Programming Tips - How can I programatically make a stack trace?

Date: 2014oct9
Language: Java

Q.  How can I programatically make a stack trace?


A.  Add this function to your code and call it when you want:

public static void stacktrace() { for (final StackTraceElement ste : Thread.currentThread().getStackTrace()) { System.out.println(ste.toString()); } }
Example use:
if (somethingIsWrong()) { stacktrace(); }