android10 / Android-CleanArchitecture-Kotlin

This is a movies sample app in Kotlin, which is part of a serie of blog posts I have written about architecting android application using different approaches.
https://fernandocejas.com/2018/05/07/architecting-android-reloaded/
4.64k stars 921 forks source link

Question: Why use Either instead of just throwing exceptions? #113

Closed klima7 closed 2 years ago

klima7 commented 2 years ago

I'm developing my own clean architecture app and I decided that my data layer is just throwing domain exceptions instead of wrapping them in some kind on Either type. I'm wondering whether wrapping exceptions is really better approach and why. It seems for me more convolutet. Is it really important and what are pros of this solution?

klima7 commented 2 years ago

I found the answer in the article connected with this repository. (Just found out about existence of this article, so sorry for stupid question)

What happens with traditional Error Handling?

Observing exceptions (try/catch blocks) and making decisions based on it that changes the control flow is a bad practice: it creates unprediction, affects our resilience and debugging becomes difficult, especially in concurrent environments. Plus going back to C-style error handling, using error codes which need to be checked by convention could be a nightmare.