DEV Community

Rasmus Larsson
Rasmus Larsson

Posted on

1

Error Handling Responsibility Principles

Principle 1

The code closest to the source of the error is responsible for providing as much detail about the error and if possible classifying it if such is needed.

Motivation: The further you get from the error the harder this becomes.

Principle 2

Code further up in the call stack is responsible for deciding on how to act on the error given the current context.

Motivation: Called code has no idea of the context.

Example

A DB error is thrown. The code closest to the error classifies it as a socket time out. This is bubbled up in the call stack which then decides to not retry because a user has decided that the query is no longer relevant.

Special Note

These principles apply not only within an in-memory call stack but also across e.g. micro-service boundaries.

Do you disagree? I would love your input.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more