What is the correct way, to handle all exceptions ...
# coroutines
p
What is the correct way, to handle all exceptions in
CoroutineScope
, that applies for all jobs? Let's say I have following:
Copy code
val scope = CoroutineScope(dispatcher + SupervisorJob())
Is following a correct way to handle all exceptions, for all jobs, lunched inside that scope?
Copy code
val handler = CoroutineExceptionHandler { _, exception ->
    println("$exception")
}
val scope = CoroutineScope(dispatcher + SupervisorJob() + handler)
d
yes, this will catch all exceptions thrown in coroutines. One exception though,
CancellationException
is not caught and is instead propagated to ensure structured concurrency is not violated (you shouldn't catch it anyways when working with coroutines except in some edge cases where cleanup is to be performed)
🍺 1