Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Beginner
Nov 1, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Use printStackTrace() method to generate stack

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)

(b) You can put following statement anywhere in your code to print the stack trace to standard error stream.
new Throwable().printStackTrace();
Deepak Pant
Thanks for your registration, follow us on our social networks to keep up-to-date