Kotlin's Rich Errors: Native, Typed Errors Without Exceptions

https://news.ycombinator.com/rss Hits: 3
Summary

At KotlinConf 2025, the Kotlin team showcased progress toward Rich Errors with union types. After years of watching languages slowly adopt patterns that Elm has championed since day one, it’s exciting to see Kotlin taking this significant step toward more explicit, type-safe error handling. And in a very “native” Kotlin way at that!I vividly remember this announcement giving my functional heart a pleasant jolt, but I haven’t found the time for a write-up until now. Better late than never, though:What Are Rich Errors in Kotlin? Link to headingKotlin’s Rich Errors feature introduces union types specifically for error handling, allowing functions to return values like String | Error - a type that can be either a String or an Error. This is a fundamental shift away from the traditional try-catch paradigm toward explicit, type-safe error handling.// Future Kotlin with Rich Errors fun parseNumber(input: String): Int | ParseError { // Returns either an Int or a ParseError } This approach makes errors part of the type system, forcing developers to handle them explicitly rather than hoping they remember to wrap everything in try-catch blocks.How this compares in Kotlin today Link to headingKotlin already ships with Result<T> in the standard library, and many teams model error domains with Arrow’s Either<Error, Value>/Validated. Rich Errors make these patterns feel native: the error space becomes part of the function type without wrappers. This reduces the need for Either-style constructs for many cases, while Arrow still remains valuable for optics, typed effects, and broader FP utilities.Familiar pattern in other ecosystems Link to headingIf you’ve used languages or libraries that embrace typed errors, the idea will feel familiar: Elm’s Result (and to some extent Maybe), Rust’s Result<T, E>, Swift’s Result<Success, Failure>, or Kotlin’s Arrow Either. Rich Errors bring this experience directly into Kotlin’s type system.Type Safety Over Runtime Surprises Link to headingTradit...

First seen: 2026-01-23 18:48

Last seen: 2026-01-23 20:48