#error-handling Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Kotlin Custom Exception + Sealed Result Pattern
For library / service code, define your own exception hierarchy. Pair with `sealed` + `when` for type-safe error handling at the call site.
Kotlin Result Type — Safe Error-Returning APIs
`Result<T>` wraps "success or thrown exception" without forcing the caller into try/catch. `runCatching { ... }` is the standard producer.
Rust Result Combinators + the ? Operator
`Result<T, E>` chains like `Option`. The `?` operator unwraps `Ok` or early-returns the `Err`, converting via `From` so callers can use one error type for many sources.
TypeScript Result / Either Type
Encode "this might fail" in the type signature instead of throwing. Force the caller to handle both branches at compile time. Better than try/catch for foreseeable failures.
Rust Box<dyn Error> — Quick Boxed Errors
If you don't want the thiserror/anyhow dependency, `Box<dyn std::error::Error>` works as a catch-all. The `?` operator promotes any concrete error via `From`.
Rust anyhow for Application Errors
`anyhow::Result<T>` is `Result<T, anyhow::Error>` — a type-erased error that captures any other error AND adds context via `.context()`. The app-author's pick (use thiserror for libraries).
Rust Custom Error Type with thiserror
The `thiserror` crate generates a clean `Error + Display + Debug` impl from an enum, with automatic `From` conversions. The library-author's error-type tool of choice.