https://kotlinlang.org logo
Title
e

Edwin Miguel

07/16/2018, 8:33 PM
Hello, currently I'm working with a legacy method that throws an exception when error occurs. I could wrap it with a new one and rethrow to an upper layer, but also, I could create a sealed class to represent the response of the method (success or error). What do you think is the best approach. I would prefer to used sealed classes (or maybe a functional Either) than rethrowing errors.
n

nfrankel

07/16/2018, 8:35 PM
I would prefer to used sealed classes (or maybe a functional Either) than rethrowing errors.
why?
What do you think is the best approach.
1. it depends. there’s no context to base any advice on 2. you already stated what you prefer. go for it
e

Edwin Miguel

07/16/2018, 8:40 PM
I would like to have a good reason why not to spread the code with try/catch blocks, maybe security concerns, etc
n

nfrankel

07/16/2018, 8:45 PM
for me, it’s perfectly fine to throw a subclass of runtime exception and catch it where it makes sense so only one try/catch block if you are a functional programmer this probably sends shivers up your spine
e

Edwin Miguel

07/16/2018, 9:06 PM
Hehe, thanks a lot for your point of view 👍 I'm gonna take it into account
👍 1
n

nfrankel

07/17/2018, 6:47 AM
but again it depends on your context if you’re an oop/java programmer this is your bread and butter if you’re a fp/haskell programmer this is weird
👍 1