What’s the difference between these two syntaxes? ...
# coroutines
s
What’s the difference between these two syntaxes?
Copy code
val scope = CoroutineScope(errorHandler)
scope.launch {
    throw SomeSillyException()
}

val scope = CoroutineScope()
scope.launch(errorHandler) {
    throw SomeSillyException()
}
d
Iirc
errorHandler
is notified and that's it.
s
in both cases the errorHandler would be notified
d
There's no real difference. The latter is just more explicit.
s
It makes sense - thanks 👍🏻
s
I prefer the
CoroutineScope(errorHandler)
variation, since every
launch
from that scope will report its unhandled exceptions in the handler. For the second variation, only for that one particular
launch
will report its unhandled in the handler...
e
The effective parent context is the union of the scope’s context and the explicitly passed one, so there is not behavioral different difference here. https://medium.com/@elizarov/coroutine-context-and-scope-c8b255d59055
s
Got it - thanks everyone for weighing in. I’m trying to fine tune my coroutine composition skills