If I have some best-effort code, I might write it ...
# coroutines
a
If I have some best-effort code, I might write it as
Copy code
try {
   foo()
} catch (ex: Exception) {
   // ignore failures, best effort
}
but if I'm inside a coroutine, will this screw up cooperative cancellation? Do I need to do something like
Copy code
try {
  foo()
} catch (ex: CancellationException) {
  throw ex
} catch (ex: Exception) {
  // ignore failures, best effort
}
?
t
yes, you do
a
I was afraid of that. Thanks. 🙂
e
that also screws up Java thread interruption
a
that also screws up Java thread interruption
Will that be handled by re-throwing CancellationException as in my second block of code?
Or are there additional changes required for the Java thread case?
e
Java uses a different InterruptedException
in general catching and failing to rethrow exceptions is a bad idea. only handle exceptions you know you can handle
a
Yeah, I'm not super happy about it either. (massive legacy codebase 🥳 )