Stay organized with collections
Save and categorize content based on your preferences.
UncaughtExceptionHandler
@FunctionalInterface interface UncaughtExceptionHandler
Known Direct 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 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 |
abstract Unit |
Method invoked when the given thread terminates due to the given uncaught exception.
|
Public methods
uncaughtException
abstract fun uncaughtException(
t: Thread,
e: Throwable
): Unit
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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Thread.UncaughtExceptionHandler\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nUncaughtExceptionHandler\n========================\n\n```\n@FunctionalInterface interface UncaughtExceptionHandler\n```\n\n|------------------------------------------------|\n| [java.lang.Thread.UncaughtExceptionHandler](#) |\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [ThreadGroup](/reference/kotlin/java/lang/ThreadGroup) |--------------------------------------------------------|---------------------------------------------| | [ThreadGroup](/reference/kotlin/java/lang/ThreadGroup) | A thread group represents a set of threads. | |\n\nInterface for handlers invoked when a `Thread` abruptly terminates due to an uncaught exception.\n\nWhen a thread is about to terminate due to an uncaught exception the Java Virtual Machine will query the thread for its `UncaughtExceptionHandler` using [getUncaughtExceptionHandler](/reference/kotlin/java/lang/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](/reference/kotlin/java/lang/Thread#getDefaultUncaughtExceptionHandler()).\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [uncaughtException](#uncaughtException(java.lang.Thread,%20kotlin.Throwable))`(`t:` `[Thread](/reference/kotlin/java/lang/Thread)`, `e:` `[Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html)`)` 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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun uncaughtException(\n t: Thread, \n e: Throwable\n): Unit\n```\n\nMethod invoked when the given thread terminates due to the given uncaught exception.\n\nAny exception thrown by this method will be ignored by the Java Virtual Machine.\n\n| Parameters ||\n|-----|-------------------------------------------------------------------------------------------------------|\n| `t` | [Thread](/reference/kotlin/java/lang/Thread): the thread |\n| `e` | [Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html): the exception |"]]