require
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Require a condition or throw a recoverable error.
Aliases: require
Syntax: requirit <expression> iace <expression>
Category#
errors
Related#
Examples#
radix/corpus/meta/requirit.fab (canonical · keyword)#
Require a condition or throw a recoverable error.
# =============================================================================
# requirit — Require a condition or throw a recoverable error.
# =============================================================================
#
# What this teaches:
# • Recoverable guard — `require <condition> throw <error>` throws into the
# function's ⇥ channel when the condition is false (en surface of `requirit`)
# • Twin of `adfirma` — `assert` is fatal; `require` is catchable by `catch`
# • Typed payload — the false-path expression is a `variant` with `causa`,
# the same shape used at constructor guard ladders
#
# Common mistakes:
# • Using `require` in a function without `⇥ E` — SEM010 `iace_requires_alternate_exit`, same as `throw`
# • Treating `require` as a test-capability gate — it is a statement, not a named fixture on `test`
#
# See also: adfirma, iace, cape, ⇥
# =============================================================================
# requirit — recoverable require statement
#
# require <condition> throw <error>
#
# GRAMMAR:
# requiritStmt :← 'requirit' expr 'iace' expr
#
# EXPECTED OUTPUT:
# empty — success-path main only (requirit.expected)
union GuardError {
Invalid { string causa }
}
fn guarded(int value) → int ⇥ GuardError {
require value > 0 throw variant Invalid { causa = "value must be positive" }
return value
}
main {
do {
const int ok ← guarded(1)
assert ok ≡ 1
}
catch err {
assert false panic "success path must not throw"
}
}
test "false path is recoverable" {
do {
const int dropped ← guarded(0)
assert false panic "false path must throw"
}
catch err {
# recovered — require entered ⇥ and catch intercepted it
}
}