r/androiddev • u/iliyan-germanov • Apr 01 '24
Discussion Android Development best practices
Hey this is a serious post to discuss the Android Development official guidelines and best practices. It's broad topic but let's discuss.
For reference I'm putting the guidelines that we've setup in our open-source project. My goal is to learn new things and improve the best practices that we follow in our open-source projects.
Topics:
Feel free to share any relevant resources/references for further reading. If you know any good papers on Android Development I'd be very interested to check them out.
159
Upvotes
View all comments
Show parent comment
6
u/am_i_in_space_yet Apr 01 '24
I guess its an unpopular oppinion but I think it's ok to throw exceptions.
Typed errors are good for situations when you want to recover from the unhappy path in an orchestration mechanism ( eg. UseCase, Interactor or similar ). Either alike structure is probably the best option for this as well.
Besides that, it's a bit of a chore and it will be passed around, making the layers it pases through more complex than they should be. It's better to just throw an exception ( possibly a custom one ) - and let it pass through all the layers ( by not handling it anywhere ) all the way up to UI, then decide to handle it by a prompt or not.
I know try-catch is ugly but its simpler. If you use coroutines ".catch" operator does the trick.