since there are no checked exceptions in kotlin, is it best to have error return values instead?
s
streetsofboston
11/10/2019, 4:17 AM
You still have exceptions that you can catch... they are just not checked.
But, if you like function-style programming, making your functions more pure by either carrying a good return value or an error value (e.g.
Either<E,T>
), that'd be better than them throwing an exception...
s
serebit
11/10/2019, 5:38 AM
Imo, exceptions should be exceptional. If your code needs to halt and catch fire when something genuinely unexpected happens, use an exception. If it's expected to happen sometimes, use either a nullable return or a sealed class return if you want more detailed information
💯 2
w
william
11/10/2019, 5:57 AM
makes sense. remind me of programming in c having result codes everywhere
Nothing prevents you to catch exception, they’re just not enforced by the compiler, unlike Java. On a functional side, adding to the excellent advice above, you could use