I’m going to leverage coroutineScope to implement a function, I found that the doc said When any child coroutine in this scope fails, this scope fails and all the rest of the children are cancelled (for a different behavior see supervisorScope)
. For the code below, the coroutineScope is susped forever after throw the exception, what’s the problem? It seems the problem is the suspendCoroutine function, if I remove the suspendCoroutine everything is ok. I think when the exception is thrown, the first launch should also be cancelled as well.
val scope = MainScope()
scope.launch {
Log.d("MainActivity", "onCreate: 11111")
try {
coroutineScope {
launch(Dispatchers.Unconfined) {
suspendCoroutine<Unit> {
Log.d("MainActivity", "onCreate: 123")
}
}
launch (Dispatchers.IO) {
delay(1000)
Log.d("MainActivity", "going to throw exception")
throw NullPointerException("123123")
}
}
} catch (e: Exception) {
Log.d("MainActivity", "onCreate: ", e)
}