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

Use Flow's catch() operator instead of try-catch #38

Merged
merged 1 commit into from
Aug 16, 2020

Conversation

shubham08gupta
Copy link
Contributor

https://kotlinlang.org/docs/reference/coroutines/flow.html#exception-transparency. According to this,
Flows must be transparent to exceptions and it is a violation of the exception transparency to emit values in the flow { ... } builder from inside of a try/catch block. This guarantees that a collector throwing an exception can always catch it using try/catch as in the previous example.

I think it's better to use Kotlin Flow's built-in catch operator. This won't affect anything according to the current code but it will be helpful if there is any change in the catch() block in the future.

https://kotlinlang.org/docs/reference/coroutines/flow.html#exception-transparency. According to this, 
Flows must be transparent to exceptions and it is a violation of the exception transparency to emit values in the flow { ... } builder from inside of a try/catch block. This guarantees that a collector throwing an exception can always catch it using try/catch as in the previous example. 

I think it's better to use Kotlin Flow's built-in catch operator. This won't affect anything according to the current code but it will be helpful if there is any change in the catch() block in the future.
Copy link
Owner

@PatilShreyas PatilShreyas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @shubham08gupta. LGTM! 🎯

@PatilShreyas PatilShreyas merged commit 61b5cd8 into PatilShreyas:master Aug 16, 2020
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

Successfully merging this pull request may close these issues.

2 participants