J.V · Java 25 practice question
A worker thread throws an exception that no catch clause on its call stack can handle. The thread has an uncaught exception handler configured and an active finally block on the stack. What happens before the thread terminates?
Check answer and explanation
Correct answer: All active finally clauses are executed, and the thread's uncaught exception handler is executed
Explanation
When no catch clause can handle an exception, the current thread is terminated, and before termination all finally clauses are executed and the thread's uncaught exception handler is executed if set.
Common trap
Finally blocks are not skipped during uncaught exception unwinding; they execute before thread termination. Finally blocks always run as the stack unwinds, even when no catch block handles the exception.
Source: JLS SE 25 §11.3. Run-Time Handling of an Exception
Checked against the cited text on 2026-11-25.