https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Dominaezzz

10/04/2019, 10:38 AM
When should I use
val scope = SupervisorScope()
over
val scope = CoroutineScope(CoroutineExceptionHandler { ctx, e -> })
?
s

streetsofboston

10/04/2019, 10:53 AM
When an exception is thrown but not caught by a child-Coroutine in a scope with a supervisor job (SupervisorScope), its other child Coroutines keep running and the scope remains active. Using a 'regular' scope with a CEH or not, the scope its Job and all its child-Coroutines will finish when one of its child-Coroutines throws but not catch an exception.
“Exceptional Exceptions for Coroutines made easy…? part II: Supervision” by Anton Spaans https://link.medium.com/V0VsGfpEv0
Providing a CEH that does nothing, does not prevent the scope from being canceled. A CEH will receive the exception instead of the uncaught-exception-handler, possibly preventing your app from crashing
d

Dominaezzz

10/04/2019, 11:01 AM
Yeah I thought as much.
10 Views