Fail Fast
“Throw Early, Handle Late: If you can’t fix it, don’t catch it.”
Our goal is to build systems that fail gracefully and are easy to troubleshoot:
- Treat exceptions as exceptional events, not as standard control flow
- Bugs should be surfaced at the source and only handled when there is context to resolve them
Throw Early (Fail Fast)
Don’t allow invalid state to travel deep into the business logic. Validate your inputs immediately at the boundaries (API/Entry points, or when calling external resources).
Being strict at the boundaries creates an internal Trust Zone—allowing core logic to remain clean and free of redundant checks for unrealistic scenarios.
Kotlin Tip: Use require() for arguments and check() for internal state.
|
|
Handle Late
Only write a catch block if you can meaningfully recover, e.g. by retrying the operation, returning a safe default, or
translating the error into a helpful message for the end user.
Do not catch an exception simply to log it and re-throw it. Instead, let the exception bubble up to a global handler that is designed for centralized logging and observability.
References
- You can find more suggestions with useful tips for Java/Kotlin here
- Fail fast system
- The Pragmatic Programmer - Assertive Programming