wood burning stoves 2.0*
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
Author

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
Greenhorn

Joined: Feb 09, 2010
Posts: 14
Hi,

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

try{
}catch(Exception e){
e.printStackTrace();
}

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;
try{
}catch(Exception e){
traces = e.getStackTrace();
}

All the best..!
Jan Hoppmann
Ranch Hand

Joined: Jul 19, 2010
Posts: 142

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
Rancher

Joined: May 22, 2012
Posts: 865
    
    5
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 !!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Stack trace
 
Similar Threads
how to programe a stack process for first in and last out!
Exception?
StackOverFlow Exception
Stack Trace
Getting two java code blocks to work together