आवश्यक
Translation status: हिन्दी reader-locale proof. Term names and code fences follow the hi pack; supporting prose may still be English.
Require a condition or throw a recoverable error.
Aliases: require
Syntax: आवश्यक <expression> इधरफेंको <expression>
Category#
errors
Related#
Examples#
radix/corpus/meta/requirit.fab (canonical · keyword)#
Require a condition or throw a recoverable error.
# =============================================================================
# आवश्यक — 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 `आवश्यक`)
# • Twin of `पुष्टि` — `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: पुष्टि, इधरफेंको, पकड़ो, ⇥
# =============================================================================
# आवश्यक — recoverable require statement
#
# require <condition> throw <error>
#
# GRAMMAR:
# requiritStmt :← 'आवश्यक' expr 'इधरफेंको' 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
}
}