Dibya Ranjan
06/11/2020, 5:04 AM*As a rule of thumb, you should not be catching exceptions in general Kotlin code.* That's a code smell.
.
I see that I can make changes to my APIs to validate and return rather than throwing and catching an exception. However, I failed to come up with a better code for one scenario.
I have a Kafka consumer, which makes a call to a web API. so I have onListen(p: Person) -> orchestrator(p: Persons) -> makeRestCall(p: Person) -> API
the exception flow here as I would do in Java is to handle all non response codes 200s. If there is an error returned from the API, I throw and exception, the orchestrator catches it. Is this an anti pattern in Kotlin? I think I am not the first person to have this issue, it would be of great help if someone can give a direction here. Thank you.Hanno
06/11/2020, 7:14 AMDibya Ranjan
06/11/2020, 7:22 AMmakeRestCall
only thing it is aware of is whether the call was successful or not.
I know my java code style is holding me down on this aspect but I was curious to know how everyone deals with this. Appreciate your help suggestions.Hanno
06/11/2020, 7:36 AMHanno
06/11/2020, 7:47 AMEvan R.
06/11/2020, 12:03 PMEvan R.
06/11/2020, 12:03 PMBrian Dilley
06/11/2020, 5:42 PMHanno
06/11/2020, 6:27 PMBrian Dilley
06/11/2020, 6:28 PMHanno
06/11/2020, 6:40 PMDibya Ranjan
06/12/2020, 2:09 AMDidn’t the article say that you should have a general exception for network call errors that you catch at the top level of the app?@Evan R., My understanding was slightly different. My assumption was there has to be top level exception handler around
onListen
.
I think the way I have coded is not that bad.