Kết xuấtvi

từ_chối

Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.

Reject a condition or throw a recoverable error.

Aliases: reject

Syntax: từ_chối <expression> ném <expression>

Category#

errors

Examples#

radix/corpus/meta/reice.fab (canonical · keyword)#

Reject a condition or throw a recoverable error.

# =============================================================================
# từ_chối — 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 `từ_chối`)
#   • 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: yêu_cầu, khẳng_định, ném, bắt, ⇥
# =============================================================================

# từ_chối — recoverable reject statement
#
# reject <condition> throw <error>
#
# GRAMMAR:
#   reiceStmt :← 'từ_chối' expr 'ném' 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
}

main {
    do {
        const int ok ← guarded(1)
        assert ok ≡ 1
    }
    catch err {
        assert false panic "success path must not throw"
    }
}

test "true path is recoverable" {
    do {
        const int dropped ← guarded(-1)
        assert false panic "true path must throw"
    }
    catch err {
        # recovered — reject entered ⇥ and catch intercepted it
    }
}