Errors
Errors in Bridje are anomalies: tags, in brj.core, over a record of details.
The categories follow cognitect.anomalies — each says what kind of failure it is, and so what a caller might do about it.
Categories
Section titled “Categories”Unavailable- The callee isn’t available — try again, maybe later.
Interrupted- The operation was interrupted —
brj.concurrent’s interruption throws this. Busy- The callee is overloaded — back off and try again.
Incorrect- The caller made a mistake — fix the call.
Forbidden- The caller isn’t allowed — fix the permissions.
Unsupported- The operation isn’t supported — don’t retry.
NotFound- The thing asked for doesn’t exist.
Conflict- The request conflicts with the current state — coordinate, then retry.
Fault- The callee has a bug — nothing the caller can do.
Host- An exception thrown by the host — a Java exception.
Throwing
Section titled “Throwing”throw(anomaly)- Throws
anomaly.throw’s return type isNothing, so it fits anywhere a value is expected.
throw(NotFound{.exnMessage "no such user"})An anomaly’s record can carry any keys; .exnMessage, a Str, is the conventional one, and becomes the exception’s message on the host.
Catching
Section titled “Catching”try: body… catch: pattern handler … finally: cleanup…- Evaluates the body; if it throws, the first
catch:pattern that matches the anomaly selects the handler. Patterns are as incase:, and a final unpaired form is the default. A pattern’s tag must be an anomaly —Thing is not an anomaly, so a catch cannot match it— and a lowercase catch-all binds anAnomaly. Thetry:as a whole is the join of its body and its handlers;finally:contributes nothing to its type.
try: findUser(id) catch: NotFound(e) nil catch: Host(e) throw(Fault{.exnMessage "lookup failed"}) finally: closeConnection()An anomaly’s keys are all optional, so a caught anomaly’s message is read with .?exnMessage(e); destructuring it, Fault{exnMessage}, is an error.
An anomaly that no pattern matches carries on up the stack.