CoroutineExceptionHandler

interface CoroutineExceptionHandler : Element (source)

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:

See handleCoroutineException.

Types

Key

companion object Key : Key<CoroutineExceptionHandler>

Key for CoroutineExceptionHandler instance in the coroutine context.

Functions

handleException

abstract fun handleException(
    context: CoroutineContext,
    exception: Throwable
): Unit

Handles uncaught exception in the given context. It is invoked if coroutine has an uncaught exception. See handleCoroutineException.

Extension Functions

cancel

fun CoroutineContext.cancel(
    cause: Throwable? = null
): Boolean

Cancels Job of this context with an optional cancellation cause. The result is true if the job was cancelled as a result of this invocation and false if there is no job in the context or if it was already cancelled or completed. See Job.cancel for details.

cancelChildren

fun CoroutineContext.cancelChildren(
    cause: Throwable? = null
): Unit

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.