Animesh Sahu
11/20/2019, 3:35 PMJobCancellationException
at once?streetsofboston
11/20/2019, 3:58 PMAnimesh Sahu
11/20/2019, 3:59 PMstreetsofboston
11/20/2019, 4:04 PMsuspend
piece of code that is currently in suspended state communicates it was cancelled. The CancellationException is thrown up from that suspended piece of code all the way to the top CoroutineScope on which the initial launch
was called. It is a special Exception, since it won’t fail any child coroutines, it just cancels them.Animesh Sahu
11/20/2019, 4:07 PMstreetsofboston
11/20/2019, 4:13 PMAnimesh Sahu
11/20/2019, 4:14 PMstreetsofboston
11/20/2019, 4:19 PMtry {
val value = someSuspendFunction()
} catch (t: Throwable) {
Log.e(TAG, t)
}
The above eats any exception, including any CancellationException and it breaks the Coroutines Structured Concurrency model.
If you want to ‘eat/forget’ any exception do it like this:
try {
val value = someSuspendFunction()
} catch (c: CancellationException) {
throw c
} catch (t: Throwable) {
Log.e(TAG, t)
}