How should errors propagate across the layers of an application?

Prepare for the Code Standards and Practices Level 1 Test. Test yourself with multiple choice questions, flashcards, and explanations. Ensure success with our comprehensive study materials!

Multiple Choice

How should errors propagate across the layers of an application?

Explanation:
Errors should be propagated across layers with meaningful context while keeping abstraction boundaries intact. When a lower layer fails, carry forward a structured error that conveys what went wrong in a way the next layer can act on, but avoid leaking internal details like database schemas, SQL, or implementation specifics. For example, a data access failure can map to a domain-level error such as DataUnavailable or ExternalResourceError, possibly with an error code and a user-friendly message for the caller, while preserving full details in logs for debugging. This preserves security and encapsulation, enables consistent handling (retries, fallbacks, user feedback), and makes debugging easier because the cause is clear without exposing internals. Letting errors bubble up with no context leaves higher layers powerless to respond appropriately. Translating everything to a single generic message robs downstream layers of actionable information and hurts both user experience and troubleshooting. Catching and swallowing errors hides problems and can lead to inconsistent states or later, harder failures.

Errors should be propagated across layers with meaningful context while keeping abstraction boundaries intact. When a lower layer fails, carry forward a structured error that conveys what went wrong in a way the next layer can act on, but avoid leaking internal details like database schemas, SQL, or implementation specifics. For example, a data access failure can map to a domain-level error such as DataUnavailable or ExternalResourceError, possibly with an error code and a user-friendly message for the caller, while preserving full details in logs for debugging. This preserves security and encapsulation, enables consistent handling (retries, fallbacks, user feedback), and makes debugging easier because the cause is clear without exposing internals.

Letting errors bubble up with no context leaves higher layers powerless to respond appropriately. Translating everything to a single generic message robs downstream layers of actionable information and hurts both user experience and troubleshooting. Catching and swallowing errors hides problems and can lead to inconsistent states or later, harder failures.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy