NOTE
Designing Exception Handling
Practical exception-handling rules: catch at meaningful boundaries, preserve context, avoid swallowing failures, and map errors once.
This is a historical learning note and may contain outdated or incomplete understanding.
Catch an exception where you can add a meaningful policy: retry, compensate, translate to a domain/API error, release resources, or terminate work safely.
Do not catch only to log and rethrow at every layer; that produces duplicate logs. Preserve the original cause when translating exceptions, and include stable context such as operation/resource IDs rather than secrets.
Do not silently swallow failures. Separate expected domain errors from programming/infrastructure failures. At service boundaries, map internal exceptions to a stable external error contract without leaking stack traces or implementation details.
Retries belong only around retryable failures and need deadlines, bounded attempts, backoff/jitter, and idempotency.