6.5 Errors
There are no exceptions. An error is a value of a type marked @error, returned through a union.
@error data NotFound { what: str }
@error enum PayError { Declined(reason: str), Fraud }
fn charge(card: Card, sum: Money) -> Receipt | PayError | NetError net {
let token = Vault.tokenize(card)? // ? propagates the errors of the call
if sum <= Money.zero() { fail PayError.Declined("zero sum") }
Bank.pay(token, sum)
}fail ereturns the errorefrom the function; the type ofeMUST be included in the return type.e?fore: T | E1 | …: on an error returns it from the function, otherwise yieldsT. The errors MUST be included in the return type of the function.e?fore: T?(without errors) returnsnonefrom a function that returns an optional.- Mandatory handling. An expression statement whose type contains an
@errortype is a compile error. Handling:match,?,!>,if … is, assignment to a variable that is then handled, or an explicit discard_ = e. - Network errors. Every rpc call, actor message and cluster operation adds
NetErrorto the result:
type NetError = Timeout | Unavailable | Cancelled | AccessDenied | ProtocolErrorProtocolError is @error data ProtocolError { msg: str, code: i32 }, where code is a gRPC status code. The notations ProtocolError.Internal (§6.6), ProtocolError.InvalidArgument (§9.4) and ProtocolError.Unimplemented are associated constants — values of this type with the codes 13, 3 and 12; they can be compared and matched in the same way as variants (D-8052; DIV-004; D-2901).
The result of a cluster operation contains NetError if the operation talks to other nodes and may fail to get an answer: among the cluster.* operations (§12.6) lock and lockFenced are such; operations executed locally (self, members, find, pick, leader, ids, now, shards) do not add NetError (D-7520).
- Trace: in profiles with
trace = trueevery?adds a frame (function, file, line) to the error; available aserr.trace().
Related diagnostics
fail-type, question-context, unhandled-error
See also
Source: docs/spec/oxl-standard.en.md