العرضar

ارم

Translation status: العربية reader-locale proof. Term names and code fences follow the ar pack; supporting prose may still be English.

Throws a recoverable error.

Syntax: ارم <expression>

Category#

errors

Examples#

radix/corpus/iace/iace-si-guard.fab (canonical · keyword)#

Conditional throw with إذا guard.

# =============================================================================
# ارم — Conditional throw with إذا guard
# =============================================================================
#
# What this teaches:
#   • Conditional throw with إذا guard.
#   • Related keywords: التقط, انهر, إذا, ⇥
#
# Common mistakes:
#   • Using `ارم إذا` without a `⇥` on the enclosing function or a `افعل/cape` wrapper — the guard sugar expands to `إذا cond { ارم val }`, which still needs an error context.
#
# See also: التقط, انهر, إذا, ⇥
# =============================================================================

# ارم with optional إذا guard
#
# ارم <value> [إذا <condicio>]
#
# GRAMMAR:
#   throwStmt :← 'ارم' expr ['إذا' expr]
#
# The optional `إذا` guard is parser sugar:
#   ارم val إذا cond  →  إذا cond { ارم val }
#
# Without the guard, ارم is unconditional (unchanged).
#
# EXPECTED OUTPUT:
#   "ok: valid input"
#   "caught: empty input"
#   "caught: negative"

fn validata(string input) → string ⇥ string {
    # Guard: throw if input is empty
    throw "empty input" if input.length() ≡ 0

    return "valid: §"(input)
}

main {
    # Happy path — guard not triggered
    do {
        const string a ← validata("hello")
        print "ok: §"(a)
    }
    catch err {
        print "unexpected: §"(err)
    }

    # Empty input — ارم إذا guard triggers
    do {
        const string b ← validata("")
        print "should not reach"
    }
    catch err {
        print "caught: §"(err)
    }

    # ارم with إذا on same line
    do {
        throw "force throw" if true
        print "should not reach"
    }
    catch err {
        print "caught: §"(err)
    }
}

radix/corpus/iace/iace.fab (canonical · keyword)#

Throws a recoverable error.

# =============================================================================
# ارم — Throws a recoverable error
# =============================================================================
#
# What this teaches:
#   • Throws a recoverable error.
#   • Related keywords: ⇥, التقط, انهر, أعد
#
# Common mistakes:
#   • Using `ارم` without a `⇥` on the enclosing function or a `افعل { ... } التقط err { ... }` wrapper — `ارم` requires an error-handling context (SEM010).
#
# See also: ⇥, التقط, انهر, أعد
# =============================================================================

# ارم — recoverable throw and التقط handler
#
# ارم <value>
# افعل { <body> }
# التقط err { <handler> }
#
# GRAMMAR:
#   throwStmt :← 'ارم' expr
#   facStmt   :← 'افعل' block catchClause?
#
# EXPECTED OUTPUT:
#   Caught error messages from افعل/cape recovery paths.
#
# BACKEND:
#   Rust/Go lowering does not emit ارم/cape yet — compile-only smoke.

main {
    # Bare ارم with نص payload
    do {
        throw "Something went wrong"
    }
    catch err {
        print "Caught:", err
    }

    # ارم with interpolated message
    const int code ← 404
    do {
        throw "Error code: §"(code)
    }
    catch err {
        print "Caught:", err
    }

    # Conditional ارم inside افعل — validation guard
    const int value ← -5
    do {
        if value ≺ 0 {
            throw "Value must be non-negative"
        }
        print "Value is valid"
    }
    catch err {
        print "Validation failed:", err
    }
}

Expected output:

Caught: Something went wrong
Caught: Error code: 404
Validation failed: Value must be non-negative