रेंडरिंगhi

cape

Translation status: हिन्दी reader-locale proof. Code fences render through the hi pipeline; prose is canonical Latin.

Starts a catch block.

Aliases: catch

Syntax: <structured-statement> cape <name> <block>

Category#

errors

Examples#

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

Starts a catch block.

# =============================================================================
# cape — Starts a catch block.
# =============================================================================
#
# What this teaches:
#   • Error recovery — `fac { … } cape err { … }` attempts a block and catches
#     errors with a named handler
#   • Guarded execution — code inside the `fac` block can `iace` errors that
#     are intercepted by the `cape` handler
#
# Common mistakes:
#   • attaching `cape` to a bare `{ }` block — `cape` only attaches to `fac` blocks and structured statements; use `fac { ... } cape err { ... }`
#
# See also: fac, iace, ⇥
# =============================================================================

# cape — catch handler on fac
#
# GRAMMAR:
#   facStmt :← 'fac' block 'cape' ident block
#
# EXPECTED OUTPUT:
#   Scalar stdout smoke (see body).
#
# BACKEND:
#   Rust/Go: fac/cape emit gap (whitelist: cape/cape.fab).
#

main {
    var int attempt  0
    do {
        attempt  attempt + 1
        if attempt > 1 {
            throw "simulated failure"
        }
        print "attempt §"(attempt)
    }
    catch err {
        print "caught"
    }
}

Expected output:

attempt 1