Repository navigation
Rule 12 Predictable failures are typed
Part two: modelling. Expected rule-breaking gets its own named exception and a clear message. Real breakdowns are handled differently.
The short form of every rule is in BUILD_PHILOSOPHY.md, which is the version that
counts. This page is the long form: why, where it shows today, and when not to use it.
"This email address already has an account" and "the database is gone" are different
kinds of problem. Handling both with catch (\Exception) turns every problem into
"something went wrong", and the person cannot do anything about it.
- Named failures:
src/Auth/UserAlreadyExists.php,src/Auth/InvalidEmailAddress.php,src/Setup/SetupLinkNotSaved.php. Each carries its data, and the message the person reads is written where it is shown. - Expected outcomes are not exceptions at all: a wrong password or an expired welcome link is a normal answer with its own page.
Inside a spike, a plain exception is fine. The rule is for core.
Domain exception, boundary. See Glossary.
Advanced Domain Architecture & Tactical DDD, Rule 5 in its course philosophy, taught in module 4, domain exception trees. Course page.