Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethrow CancellationException in try-catch blocks for coroutines #17

Open
Obolrom opened this issue Mar 14, 2024 · 1 comment
Open

Rethrow CancellationException in try-catch blocks for coroutines #17

Obolrom opened this issue Mar 14, 2024 · 1 comment

Comments

@Obolrom
Copy link

Obolrom commented Mar 14, 2024

Here is a code from repository LoginVM

Screenshot from 2024-03-14 12-57-56

The CancellationException should be re-thrown in a catch block when we use try-catch in coroutines.

Why?

Kotlin doc
Medium article
Florina Muntenescu's article - Cancellation in coroutines

@Obolrom
Copy link
Author

Obolrom commented Mar 20, 2024

If I am not mistaken, this can lead to UI bugs

The problem here is we do not handle CancellationException. In the catch block, the consumeException is called (the implementation)
Thus, alertFactory.unknownErrorAlert(closable, e = exception) line will be called. However, the cancellation event should not be the trigger for showing an alert

My proposition here at least do not call consumeException(e, templateKey) and errorIndicator?.postValue(true) if CancellationException has occurred, to avoid showing an unnecessary alert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant