Knowing the current stack trace is very useful in java. It helps in debugging and troubleshooting problems.
As you don’t want the stack trace directly printed out the best way is to use
This function returns an array of current stack trace elements of this thread. The first element of the array i.e. top of the stack is the most recent method invocation in the sequence. The last element of the array i.e. bottom of the stack is the least recent method invocation in the sequence.
If this thread has not started, or has been terminated then this method will return a zero-length array.