File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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 !!!
I agree. Here's the link:
subject: Stack trace
It's not a secret anymore!