public class CoroutineExceptionHandlerKt
Modifier and Type | Method and Description |
---|---|
static CoroutineExceptionHandler |
CoroutineExceptionHandler(kotlin.jvm.functions.Function2<? super error.NonExistentClass,? super java.lang.Throwable,kotlin.Unit> handler)
Creates new
interface CoroutineExceptionHandler instance. |
static void |
handleCoroutineException(NonExistentClass context,
java.lang.Throwable exception,
Job caller)
Helper function for coroutine builder implementations to handle uncaught exception in coroutines.
|
public static void handleCoroutineException(NonExistentClass context, java.lang.Throwable exception, Job caller)
Helper function for coroutine builder implementations to handle uncaught exception in coroutines.
It tries to handle uncaught exception in the following way: If current exception is CancellationException, it's ignored: CancellationException is a normal way to cancel coroutine.
If there is a interface Job
in the context and it's not a caller, then Job.cancel
is invoked.
If invocation returned true
, method terminates: now interface Job
is responsible for handling an exception.
Otherwise, If there is interface CoroutineExceptionHandler
in the context, it is used. If it throws an exception during handling
or is absent, all instances of interface CoroutineExceptionHandler
found via ServiceLoader and Thread.uncaughtExceptionHandler are invoked
public static CoroutineExceptionHandler CoroutineExceptionHandler(kotlin.jvm.functions.Function2<? super error.NonExistentClass,? super java.lang.Throwable,kotlin.Unit> handler)
Creates new interface CoroutineExceptionHandler
instance.
handler
- a function which handles exception thrown by a coroutineinterface CoroutineExceptionHandler