MI

Mixed

A pragmatic mix of Try/Catch and Result Types suitable for modern applications.

Details

Language / Topic
_UUniversal
Category
Error Handling

Rules

balanced

Mixed Error Handling

- Combine exceptions for unexpected failures with Result/Either types for expected business errors.
- Use exceptions for infrastructure failures (network, I/O, OOM) and result types for domain validation errors.
- Never swallow exceptions silently — always log or propagate with context.

Mixed Error Handling

- Use exceptions for truly exceptional conditions (infrastructure failures, programming errors) and Result/Either types for expected business-logic failures (validation, not-found, permission denied).
- Wrap third-party library exceptions at module boundaries into your own domain-specific error types.
- Always attach context (operation name, input values, timestamps) when re-throwing or wrapping errors.
- Use a centralized error handler for cross-cutting concerns (logging, monitoring, user-facing messages).
- Prefer typed error enums or union types over generic error strings for pattern matching and exhaustiveness checks.
- Never use exceptions for control flow — reserve them for truly unexpected states.