You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Caller won't forget to handle the cancellation result from Call.Failure(throwable)
Additional context
Rethrow CancellationException might be a normal practice on Coroutines. I found these articles
... we catch CancellationException just to execute some actions when a coroutine has been cancelled, but we throw it again to avoid stopping the cancellation.
... in case you want to catch a generic Exception, you should remember to rethrow it in case its actual type is CancellationException otherwise you’ll also suppress the cancellation of coroutines.
... Do note that if something throws CancellationException you are generally expected to rethrow it so upstream objects are notified about the cancellation
Feature request
Type
Improvement - make what we have better
Is your feature request related to a problem?
After the suspending functionality PR, a
Call.Failure
will be returned even if it's from a Kotlin CancellationException:that means callers need to handle this canceled result to prevent some error popup might be presented to users unexpectedly.
Describe the solution you'd like
Rethrow
CancellationException
to the caller, and thisCancellationException
will be ignored by the coroutines' exception handlers.The benefits of this change
Call.Failure(throwable)
Additional context
Rethrow CancellationException might be a normal practice on Coroutines. I found these articles
... we catch CancellationException just to execute some actions when a coroutine has been cancelled, but we throw it again to avoid stopping the cancellation.
... in case you want to catch a generic Exception, you should remember to rethrow it in case its actual type is CancellationException otherwise you’ll also suppress the cancellation of coroutines.
from Kotlin Coroutines in Android — Part 5
... Do note that if something throws CancellationException you are generally expected to rethrow it so upstream objects are notified about the cancellation
from How to ignore JobCancellationException?
Also, this one is related to our topic. Kotlin: How to bypass CancellationException
The text was updated successfully, but these errors were encountered: