15.4 · throws, Result, typed throws and mapping errors at boundaries

Errors are part of an API. How you model them decides whether callers can react correctly, or just show “Something went wrong”.

Mental model. Keep low-level errors inside their layer and expose a small set of meaningful errors at each boundary, with enough information to act on.

Modelling failure

Which mechanism to use, and where to translate errors.

  1. How do you model errors in Swift: throws, Result, optionals and typed throws, and how do you translate them at layer boundaries? 15.4.1 · L3
    Pick the mechanism by what the caller can do. An optional says “there may be no value” and nothing more (a lookup that finds nothing is not an error). throws…

More in Architecture & API design