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

tateisu

11/09/2018, 6:26 AM
this is full stack trace.
g

gildor

11/09/2018, 6:30 AM
This is because of coroutineScope
t

tateisu

11/09/2018, 6:33 AM
I believe launch{} requires something kind of CoroutineScope, but other type of scope builder raises same result. how to fix it?
g

gildor

11/09/2018, 6:35 AM
Exactly, you just all the time tries to hide you async code
you shouldn’t do this
and use parent coroutine scope instead
I don’t know what exactly you want to achive, as I said, so hard to give you advice
t

tateisu

11/09/2018, 6:37 AM
I would like to see the smallest example that uses CoroutineExceptionHandler. Is that deprecated?
g

gildor

11/09/2018, 6:37 AM
No, it is not
just do not use coroutineScope function which has different semantics
use GlobalScope or some parent scope for those examples
t

tateisu

11/09/2018, 6:40 AM
Ok, this worked. thanks.
Copy code
GlobalScope.launch( handler)  {
        error("inside launch")
    }
    delay(1000)
CoroutineExceptionHandler can't cooperative with structured concurrency?
g

gildor

11/09/2018, 6:42 AM
Also instead you can make your test coroutines exception handler function extension to coroutine scope, this is how this should work in real life rather than use GlobalScope
But it's of course fine just if you want to play with some function
CoroutineExceptionHandler can't cooperative with structured concurrency?
It can, but you should use supervision scope otherwise parent will be cancelled in case of error
t

tateisu

11/09/2018, 6:57 AM
now I checked SupervisorCoroutine's code and I see it have override fun childCancelled(cause: Throwable): Boolean = false . this is reason why it is not help that just using outer context + SupervisorJob . thanks.
4 Views