reject
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Reject a condition or throw a recoverable error.
Aliases: reject
Syntax: reject <expression> throw <expression>
Category#
error
Related#
Examples#
radix/corpus/reference/keyword/reice/reice.fab (canonical · keyword)#
Reject a condition or throw a recoverable error.
# =============================================================================
# reject — Reject a condition or throw a recoverable error.
# =============================================================================
#
# What this teaches:
# • Reject guard — `reject <condition> throw <error>` throws into the
# function's ⇥ channel when the condition is true (en surface of `reject`)
# • Boolean opposite of `require` — `require not (p) throw e` becomes
# `reject p throw e`; no hand-rolled negation
# • Typed payload — the true-path expression is a `variant`, the same shape
# used at constructor guard ladders
#
# Common mistakes:
# • Using `reject` in a function without `⇥ E` — SEM010 `iace_requires_alternate_exit`, same as `throw`
# • Reading `reject` as `require` — it fails when the condition HOLDS
#
# See also: require, assert, throw, catch, ⇥
# =============================================================================
# reject — recoverable reject statement
#
# reject <condition> throw <error>
#
# GRAMMAR:
# reiceStmt :← 'reject' expr 'throw' expr
#
# EXPECTED OUTPUT:
# empty — success-path main only (reice.expected)
union GuardError {
Invalid {
string causa
}
}
fn guarded(int value) → int ⇥ GuardError {
reject value ≺ 0 throw variant Invalid { causa = "value must not be negative" }
return value
}
test "true path is recoverable" {
do {
let int dropped ← guarded(-1)
assert false panic "true path must throw"
}
catch err {
# recovered — reject entered ⇥ and catch intercepted it
}
}
main {
do {
let int ok ← guarded(1)
assert ok ≡ 1
}
catch err {
assert false panic "success path must not throw"
}
}radix/corpus/reference/reject/reice/reice-iace-reject.fab (supporting · reject)#
Reject always names its payload with throw; the missing particle is refused by name.
# =============================================================================
# reject — a reject guard must name its payload
# =============================================================================
#
# What this teaches:
# • `reject cond throw err` always carries the `throw` particle (en `throw`) and
# the error value to throw. The particle is mandatory, so a guard that drops
# it is refused by name (PARSE001 reice_iace).
# • `reject` is the boolean twin of `require`: it desugars to
# `if (cond) { throw err }`, failing when the condition holds. There is no
# recoverable failure without something to throw.
#
# Common mistakes:
# • writing the guard as a bare condition — add `throw <error>` after it.
# =============================================================================
main {
reject 1 ≡ 2
}Expected: compilation rejects this example.