Norbi
04/04/2024, 4:35 PMSam
04/04/2024, 6:02 PMSam
04/04/2024, 6:04 PMawait()
โค๏ธ๐Sam
04/04/2024, 6:07 PMNorbi
04/05/2024, 7:50 AMtry {
// do anything
} catch (e: Throwable) {
if (e is CancellationException) currentCoroutineContext().ensureActive()
handleException(e)
}
described in the last comment and the one currently in the kdoc:
try {
deferred.await()
} catch (e: CancellationException) {
currentCoroutineContext().ensureActive() // throws if the current coroutine was cancelled
processException(e) // if this line executes, the exception is the result of `await` itself
}
Thanks.Sam
04/05/2024, 8:01 AMcatch (e: CancellationException
, so it's similar to the one with if (e is CancellationException)
. If you catch all throwables and omit the is
check, as I did in my article, cancellations will be able to take precedence over real errors. Narrowing the catch clause or including the is
check are both ways to avoid that.Norbi
04/05/2024, 8:05 AMcatch
clauses.
I need a rest, reading through the above issue you linked and checking all related things has really drained my brain ๐
(Just for reference, I edited my comment above to make it clear which two "variants" I have referred to...)Norbi
04/05/2024, 10:07 AM