https://kotlinlang.org logo
Title
a

Andrei

06/07/2018, 10:51 AM
Does Exception/Throwable have a special status of same kind? Would it be okay to carry an additional state and functionality within Exception class?
k

karelpeeters

06/07/2018, 10:53 AM
Sure, there's no problem with that.
a

Andrei

06/07/2018, 10:54 AM
Java's Exception seems to follow pattern of no additional state nor methods. I have no clue if it's a contract of some kind or just coincidence.
I'm actually trying to convince people not to put any extra stuff in exception classes.
But Serialization is the only argument I got so far
k

karelpeeters

06/07/2018, 10:56 AM
Well the saying goes "don't use exceptions for control logic", so if you're going to be catching exceptions and get information out of the in the
catch
block maybe it's better to return some kind of result class.
a

Andrei

06/07/2018, 11:05 AM
No they got additional methods for logging and persistence within Exception. Which feels odd to me.
k

Katie Levy

06/07/2018, 4:39 PM
You could look into error handling with Arrow with a Try or Either object https://arrow-kt.io/docs/patterns/error_handling/
👍 1