Stack trace is a kind of call stack, which maintains the call sequence of methods at any given point in time. Throwable class in Java provides a method called “printStackTrace()” which can be used to print out the entire stack trace. You can use this method during debugging complex bug as it prints out the entire stack trace to the standard error stream.
There are a couple of ways of using this method:
a)You can call this method from the catch() block. This is the most common usage of this method.
catch (Throwable t){ t.printStackTrace();}
(b) You can put following statement anywhere in your code to print the stack trace to standard error stream.
new Throwable().printStackTrace();