Michael Friend
02/18/2020, 8:35 PMtry {
exceptionalMethod()
catch (e: Exception) {
if (e is CancellationException) {
throw e
}
// handle other exceptions
}
Would it be worth writing a some sort of top level function similar to runCatching that does the above? Or are there cleaner solutions?Michael Friend
02/18/2020, 8:37 PMEither
in Arrow instead of throwing exceptions from suspend functions, I’d rather not go through the effort of convincing my team to bring in a new librarykevin.cianfarini
02/18/2020, 8:37 PMMichael Friend
02/18/2020, 8:38 PMMichael Friend
02/18/2020, 8:39 PMstreetsofboston
02/18/2020, 8:47 PMcatch (t: Throwable)
clause….bdawg.io
02/18/2020, 8:58 PMinline fun <R> runCancellable(block:
() -> R) = runCatching(block).onFailure {
if (it is CancellationException) {
throw it
}
}
streetsofboston
02/18/2020, 9:01 PMrunCatching
variant that already did the rethrowing of a CancellationException …. 🙂Michael Friend
02/18/2020, 9:04 PMstreetsofboston
02/18/2020, 9:07 PMrunCatching
does just that and when used in Coroutines, using runCatching
may cause serious issues (cancellations not propagated). May be worth reporting this as an issue….Michael Friend
02/18/2020, 9:15 PMstreetsofboston
02/18/2020, 9:18 PMrunCatching
variation (with slightly different name) that does not catch a CancallationException and re-throws it instead.
And a lint-warning if the code contains a plain runCatching inside a Coroutine (suspendable code), urging the user to use the new one instead (that rethrows a CancellationException)Michael Friend
02/18/2020, 9:20 PMstreetsofboston
02/18/2020, 9:21 PMstreetsofboston
02/18/2020, 9:37 PM