Stay organized with collections
Save and categorize content based on your preferences.
Thread.UncaughtExceptionHandler
public
static
interface
Thread.UncaughtExceptionHandler
java.lang.Thread.UncaughtExceptionHandler
|
Known indirect subclasses
ThreadGroup |
A thread group represents a set of threads.
|
|
Interface for handlers invoked when a Thread
abruptly
terminates due to an uncaught exception.
When a thread is about to terminate due to an uncaught exception
the Java Virtual Machine will query the thread for its
UncaughtExceptionHandler
using
Thread.getUncaughtExceptionHandler()
and will invoke the handler's
uncaughtException
method, passing the thread and the
exception as arguments.
If a thread has not had its UncaughtExceptionHandler
explicitly set, then its ThreadGroup
object acts as its
UncaughtExceptionHandler
. If the ThreadGroup
object
has no
special requirements for dealing with the exception, it can forward
the invocation to the default uncaught exception handler.
Summary
Public methods
uncaughtException
public abstract void uncaughtException (Thread t,
Throwable e)
Method invoked when the given thread terminates due to the
given uncaught exception.
Any exception thrown by this method will be ignored by the
Java Virtual Machine.
Parameters |
t |
Thread : the thread |
e |
Throwable : the exception |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# Thread.UncaughtExceptionHandler\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \n\nThread.UncaughtExceptionHandler\n===============================\n\n\n`\npublic\nstatic\n\n\ninterface\nThread.UncaughtExceptionHandler\n`\n\n\n`\n\n\n`\n\n|-------------------------------------------|\n| java.lang.Thread.UncaughtExceptionHandler |\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [ThreadGroup](/reference/java/lang/ThreadGroup) |-------------------------------------------------|---------------------------------------------| | [ThreadGroup](/reference/java/lang/ThreadGroup) | A thread group represents a set of threads. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nInterface for handlers invoked when a `Thread` abruptly\nterminates due to an uncaught exception.\n\nWhen a thread is about to terminate due to an uncaught exception\nthe Java Virtual Machine will query the thread for its\n`UncaughtExceptionHandler` using\n[Thread.getUncaughtExceptionHandler()](/reference/java/lang/Thread#getUncaughtExceptionHandler()) and will invoke the handler's\n`uncaughtException` method, passing the thread and the\nexception as arguments.\nIf a thread has not had its `UncaughtExceptionHandler`\nexplicitly set, then its `ThreadGroup` object acts as its\n`UncaughtExceptionHandler`. If the `ThreadGroup` object\nhas no\nspecial requirements for dealing with the exception, it can forward\nthe invocation to the [default uncaught exception handler](/reference/java/lang/Thread#getDefaultUncaughtExceptionHandler()). \n**See also:**\n\n- [Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler)](/reference/java/lang/Thread#setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler))\n- [Thread.setUncaughtExceptionHandler(UncaughtExceptionHandler)](/reference/java/lang/Thread#setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler))\n- [ThreadGroup.uncaughtException(Thread, Throwable)](/reference/java/lang/ThreadGroup#uncaughtException(java.lang.Thread,%20java.lang.Throwable))\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[uncaughtException](/reference/java/lang/Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread,%20java.lang.Throwable))`(`[Thread](/reference/java/lang/Thread)` t, `[Throwable](/reference/java/lang/Throwable)` e) ` Method invoked when the given thread terminates due to the given uncaught exception. |\n\nPublic methods\n--------------\n\n### uncaughtException\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void uncaughtException (Thread t, \n Throwable e)\n```\n\nMethod invoked when the given thread terminates due to the\ngiven uncaught exception.\n\nAny exception thrown by this method will be ignored by the\nJava Virtual Machine.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----|-----------------------------------|\n| `t` | `Thread`: the thread \u003cbr /\u003e |\n| `e` | `Throwable`: the exception \u003cbr /\u003e |"]]