CoroutineExceptionHandler
An optional element on the coroutine context to handle uncaught exceptions.
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 Job in the context, then Job.cancel is invoked;
- all instances of CoroutineExceptionHandler found via ServiceLoader are invoked;
- and current thread’s Thread.uncaughtExceptionHandler is invoked.
Types
companion object Key : Key<CoroutineExceptionHandler> Key for CoroutineExceptionHandler instance in the coroutine context. |
Functions
abstract fun handleException( Handles uncaught exception in the given context. It is invoked if coroutine has an uncaught exception. See handleCoroutineException. |
Extension Functions
fun CoroutineContext.cancel( Cancels Job of this context with an optional cancellation cause. The result is |
|
fun CoroutineContext.cancelChildren( Cancels all children of the Job in this context with an optional cancellation cause. It does not do anything if there is no job in the context or it has no children. See Job.cancelChildren for details. |