How do I trace methods?
Hi All,
I'm working on an vast application. I want to know the list of methods that's called before a particular method is called. Something like Exception.printStackTrace() method. During runtime, when a particular method is called, I want to list down all the methods that's called in order before this particular method is called.
Your help is appreciated.
Best Regards,
Ali.
[412 byte] By [
ASIA_Alia] at [2007-11-26 19:06:02]

Well, it's always been possible to just say "new Exception().printStackTrace()." The object doesn't need to be thrown to contain a useful stack trace.
But in recent Java versions, you can call dumpStack() on a Thread to print a trace, and you can also call Thread.getStackTrace() to get an array of StackTraceElement objects, which describe each stack frame nicely. Use the static method Thread.currentThread() to get the currently executing Thread. and call dumpStackTrace()
Thread.currentThread().dumpStackTrace()