Dmitry Khasanov
12/10/2019, 12:10 PMrunBlocking {
suspendCancellableTimeoutCoroutine()
}
2. app doesn't crash
runBlocking {
launch {
suspendCancellableTimeoutCoroutine()
}
}
3. app doesn't crash, but I don't see stacktrace in logcat
runBlocking {
val handler = CoroutineExceptionHandler { _, e -> e.printStackTrace() }
launch(handler) {
suspendCancellableTimeoutCoroutine()
}
}
4. This is the behavior that I have now, it works as needed
runBlocking {
try {
suspendCancellableTimeoutCoroutine()
} catch(e: CancellableException) {
e.printStackTrace()
}
}
Could anyone explain to me 2 and 3, please?yousefa2
12/10/2019, 12:21 PMlaunch coroutine consumes the cancellation exception and doesn’t propagate it to its parent (runBlocking).
In 1, no one is consuming the exception so it ends up being propagated up the chain and unhandled exception = crash.Dmitry Khasanov
12/10/2019, 12:28 PMval handler is not used because launch consumes the exception?yousefa2
12/10/2019, 12:32 PMDmitry Khasanov
12/10/2019, 12:36 PMyousefa2
12/10/2019, 12:44 PMDmitry Khasanov
12/10/2019, 12:48 PM