public CoroutineExceptionHandler
An optional element in the coroutine context to handle uncaught exceptions.
Normally, uncaught exceptions can only result from coroutines created using BuildersKt.launch builder.
A coroutine that was created using BuildersKt.async always catches all its exceptions and represents them
in the resulting interface Deferred object.
By default, when no handler is installed, uncaught exception are handled in the following way:
If exception is CancellationException then it is ignored (because that is the supposed mechanism to cancel the running coroutine)
Otherwise:
if there is a interface Job in the context, then Job.cancel is invoked;
Otherwise, all instances of interface CoroutineExceptionHandler found via ServiceLoader
and current thread's Thread.uncaughtExceptionHandler are invoked.
| Modifier and Type | Interface and Description |
|---|---|
static class |
CoroutineExceptionHandler.Key
Key for
interface CoroutineExceptionHandler instance in the coroutine context. |
| Modifier and Type | Field and Description |
|---|---|
static CoroutineExceptionHandler.Key |
Key
Key for
interface CoroutineExceptionHandler instance in the coroutine context. |
| Modifier and Type | Method and Description |
|---|---|
void |
handleException(NonExistentClass context,
java.lang.Throwable exception)
Handles uncaught exception in the given context. It is invoked
if coroutine has an uncaught exception.
|
static CoroutineExceptionHandler.Key Key
Key for interface CoroutineExceptionHandler instance in the coroutine context.
interface CoroutineExceptionHandler