Custom Exceptions & Chaining
Define domain-specific exception types and preserve the original cause when wrapping lower-level failures.
Generic exceptions like RuntimeException or IllegalStateException tell a caller that something failed but nothing about what, in the language of your domain. Custom exception types — InsufficientFundsException, OrderNotFoundException — turn failures into named, catchable concepts that callers can handle selectively and that read clearly in logs and stack traces. The companion technique, exception chaining, ensures that wrapping a low-level failure in a domain-level one doesn't throw away the evidence of what originally went wrong.
A receipt that says "delivery failed — caused by: truck breakdown — caused by: engine fault". Each layer adds context without losing the root cause.