how to Get current stack trace in Java?

i am new to the java can you please tell me how can we find the stack trace in java,is there any method present in java for finding stacktrace.

for finding stack trace  You can use Thread.currentThread().getStackTrace() method 

 

That returns an array of StackTraceElements that represent the current stack trace of a program

 

eg:

 

for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {

    

System.out.println(ste);

}