Typed errors
Functional programming commonly advocates for explicitly stating potential errors in a function’s type signature, a practice enforced at compile time to encourage proactive error management. This approach is similar to Java’s checked exceptions, where errors must be either handled or propagated to avoid compilation failure.
Kotlin, along with many contemporary languages, favors unchecked exceptions. This choice places the responsibility of understanding and managing anticipated errors on the programmer, usually through documentation or code reviews, or with fallback try-catch blocks in the outer layers of the application to prevent throwing unhandled exceptions to the caller.
Typed errors offer a more transparent alternative, integrating error handling as an essential component of a function’s definition.
“Logical failures” are domain-specific, predictable outcomes that do not meet success criteria. For example, in a user...