Exception boundaries
standardintermediateAn exception boundary is the one deliberate place — an API handler, a job entry point — where every exception from the code it calls is caught and translated into one stable, intentional response, instead of leaking internal detail outward.
Think of it as
A boundary is a translation desk at a border crossing, not a wall stopping everything — code beneath it can raise whatever specific exceptions make sense internally; the boundary is the one place that converts all of them into a small, stable set of responses the outside world actually understands.
What we're doing: Wrap a call that can raise an internal ValueError with a boundary that translates it into one stable ExternalAPIError, preserving the original as the cause.
- 5
- call_external_api raises whatever specific exception makes sense internally — here, a plain ValueError.
- 11
- api_boundary is the one place that catches it and translates it into one stable ExternalAPIError.
- 12
- from e preserves the original as __cause__, so nothing is lost — only the outward-facing type changes.
boundary caught: upstream call failed: payload requiredWhy this works: call_external_api is free to raise ValueError, TypeError, or any other exception that fits its own logic — api_boundary is the single place that catches those and re-raises one stable ExternalAPIError, so every caller of api_boundary only ever needs to handle one exception type, regardless of how many different failures can happen underneath it.
Remember: Put one broad catch at the edge of a system — not scattered through internal code — and translate everything into a stable, intentional response there.
See also: error propagation · raise from · user facing vs internal errors

