3 ms·
I like the functional approach with Try, basically the exception becomes part of the return type, and the code chooses to either return an exception or the actu
by dtech 8y ago
I like the functional approach with Try, basically the exception becomes part of the return type, and the code chooses to either return an exception or the actual value.
fun doSomething(arg: X): Try<Y>
Since the return signature needs adjusting, this leads to developers very consciously making the choice to either handle the error in the function, therefore avoiding adjusting the return type, or let the caller deal with it if it isn't logical to handle the error there.
- wool_gather 8y agoIs this the same as `Result<Y>` (where `Result` is a sum type that contains either a value of `Y` or an "Error")? I haven't see it called `Try` before.
- dtech 8y agoIt's a common name for the concept in Java, Scala, and to a lesser extend Javascript land. But it's just a name for a `T | Exception` type.