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

ribesg

02/25/2021, 10:10 AM
I have a custom scope built like this
Copy code
CoroutineScope(Dispatchers.Default + CoroutineExceptionHandler { _, e ->
                    log.error("Uncaught error in scope", e)
                })
But it looks like when an error occurs, or rather after a few errors, coroutines basically stop like if the scope was dead or something. Eveyrthing seems stuck. Does calling the CoroutineExceptionHandler cancel the scope’s job or something? Do I need to specify a
+ SupervisorJob()
when building the scope? I don’t really understand what’s happening
k

krzysztof

02/25/2021, 11:01 AM
What you describe is standard
Job()
behavior - when error occurs, parent cancel child jobs and propagates error up (until scope reached). When that happens (and scope is cancelled) you no longer can use it. And yes, using SupervisorJob replaces that behavior - it’ll not cancel other children and stop error propagation
☝️ 1
r

ribesg

02/25/2021, 1:01 PM
Thanks! I guess I just didn’t expect a CoroutineScope to have a
Job
and not a
SupervisorJob
by default
l

louiscad

02/25/2021, 9:45 PM
@ribesg
MainScope()
will use a
SupervisorJob
though.
👍 1
2 Views