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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read 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