handleCoroutineException

fun handleCoroutineException(
    context: CoroutineContext,
    exception: Throwable
): Unit
(source)

Helper function for coroutine builder implementations to handle uncaught and unexpected exceptions in coroutines, that could not be otherwise handled in a normal way through structured concurrency, saving them to a future, and cannot be rethrown. This is a last resort handler to prevent lost exceptions.

If there is CoroutineExceptionHandler in the context, then it is used. If it throws an exception during handling or is absent, all instances of CoroutineExceptionHandler found via ServiceLoader and Thread.uncaughtExceptionHandler are invoked.