Java Thread getStackTrace() method21 Mar 2025 | 1 min read The getStackTrace() method of thread class returns an array of stack trace elements representing the stack dump of the thread. The first element of an array represents the top of the stack which is the last method invocation in the sequence. The last element of the array represents the bottom of the stack which is the first method invocation in the sequence. SyntaxReturnIt is an array of StackTraceElement, each represents one stack frame. ExceptionSecurityException:This exception throws if a security manager exists and its checkPermission method doesn't allow getting the stack trace of the thread. ExampleOutput: Displaying Stack trace using StackTraceElement in Java java.lang.Thread.getStackTrace(Thread.java:1559) JavaGetStackTraceExp.third(JavaGetStackTraceExp.java:17) JavaGetStackTraceExp.second(JavaGetStackTraceExp.java:13) JavaGetStackTraceExp.first(JavaGetStackTraceExp.java:9) JavaGetStackTraceExp.main(JavaGetStackTraceExp.java:5) Next TopicMultithreading Java |
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India