since there are no checked exceptions in kotlin, i...
# announcements
w
since there are no checked exceptions in kotlin, is it best to have error return values instead?
s
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
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
makes sense. remind me of programming in c having result codes everywhere
p
m
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
Result
from standard lib (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-result/index.html) or
Either
if using Arrow (https://arrow-kt.io/docs/arrow/core/either/#either)