This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes Stack trace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Stack trace" Watch "Stack trace" New topic

Stack trace

duhit Choudhary
Ranch Hand

Joined: Apr 01, 2012
Posts: 64
hi all,
Can anybody tell me how to get stack track of the java program in order to get the program flow?
Thanks in Advance.
ganapathi sundaram

Joined: Feb 09, 2010
Posts: 14

you can use printStackTrace() of the method from the exception object.

}catch(Exception e){

As well, if you want to read entire stack trace to store it in another variable , you can try below

public java.lang.StackTraceElement[] getStackTrace();

StackTraceElement[] traces = null;
}catch(Exception e){
traces = e.getStackTrace();

All the best..!
Jan Hoppmann
Ranch Hand

Joined: Jul 19, 2010
Posts: 147

The current thread has a getStackTrace()-method as well.

Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
Ivan Jozsef Balazs

Joined: May 22, 2012
Posts: 970
It is not even necessary to catch an exception in order to access the stack trace.

duhit Choudhary
Ranch Hand

Joined: Apr 01, 2012
Posts: 64
thanks to all of you.. i'll try to do all of your methods and will see which one is working for me !!!
wood burning stoves
subject: Stack trace
It's not a secret anymore!