bnn
11/29/2019, 4:03 AMsuspend fun foo(): Foo {
return runCatching {
// do something with calling other suspend functions
Foo()
}.getOrElse { exception ->
// do somethiing
Foo()
}
}
The code example above will not propagate CancellationException to caller.
Is it OK?
Or would I better to consider propagate CancellationException, like
suspend fun foo(): Foo {
return runCatching {
// do something with calling other suspend functions
Foo()
}.getOrElse { exception ->
if (exception is CancellationException) {
throw exception
}
// do something
Foo()
}
}
In my opinion, suspend functions are better to propagate CancellationException.
But, when we use runCatching inside it, there might be kind of boilerplate like above. Are there idiomatic ways to handle coroutines cancellation with runCatching. Or should I avoid to use it inside suspend function?pg
12/03/2019, 11:49 AM