崩潰
Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.
Raises a fatal error or panic.
Syntax: 崩潰 <expression>
Category#
errors
Related#
Examples#
radix/corpus/mori/mori-si-guard.fab (canonical · keyword)#
Conditional fatal abort with 若 guard.
# =============================================================================
# 崩潰 — Conditional fatal abort with 若 guard.
# =============================================================================
#
# What this teaches:
# • fatal abort with `崩潰` — unconditional and conditional (`若` guard) forms
# • invariant enforcement — using `崩潰` with guards to validate function preconditions
# • the `若` guard is parser sugar for `若 cond { 崩潰 "msg" }`
#
# Common mistakes:
# • Using 崩潰 for recoverable errors — use 拋出 with a 若 guard and ⇥ for recoverable failure paths instead.
#
# See also: 拋出, 則, 若
# =============================================================================
# 崩潰 with optional 若 guard
#
# 崩潰 <nuntius> [若 <condicio>]
#
# GRAMMAR:
# abortStmt :← '崩潰' expr ['若' expr]
#
# The optional `若` guard is parser sugar:
# 崩潰 "msg" 若 cond → 若 cond { 崩潰 "msg" }
#
# Without the guard, 崩潰 is unconditional (unchanged).
#
# EXPECTED OUTPUT:
# "within range"
# "positive"
# "not empty"
fn clamp(int x, int min, int max) → int {
# Guard: abort if min > max — invariant violation
panic "range inverted" if min ≻ max
# Guard: abort if value out of range
panic "value out of range" if x ≺ min or x ≻ max
return x
}
fn accessus(list<int> res, int index) → int {
# Unconditional 崩潰 — unchanged form
if index ≺ 0 or index ≥ res.length() {
panic "index out of bounds"
}
return res[index]
}
main {
# Happy path — guards not triggered
const int n ← clamp(5, 0, 10)
print "within range"
# Happy path — empty list guard not triggered
const list<int> xs ← [1, 2, 3]
const int y ← accessus(xs, 1)
print "positive"
const list<int> ys ← [42]
const int z ← accessus(ys, 0)
print "not empty"
}radix/corpus/mori/mori.fab (canonical · keyword)#
Raises a fatal error or panic.
# =============================================================================
# 崩潰 — Raises a fatal error or panic.
# =============================================================================
#
# What this teaches:
# • fatal unrecoverable abort with `崩潰` — halts execution with an error message
# • invariant checking — using `崩潰` for divisor and bounds checks
#
# Common mistakes:
# • Using 崩潰 for recoverable errors — use 拋出 with ⇥ for recoverable failure paths instead.
#
# See also: 拋出, 則
# =============================================================================
# 崩潰 — fatal unrecoverable abort
#
# 崩潰 <nuntius>
#
# GRAMMAR:
# abortStmt :← '崩潰' expr
#
# EXPECTED OUTPUT:
# Happy-path division and 列表 access; 崩潰 paths are commented out.
fn divide(int a, int b) → float {
# Use 崩潰 for invariant violations
if b ≡ 0 {
panic "divisio per nihilum"
}
return (a ↦ float) / (b ↦ float)
}
fn accipe(list<int> numeri, int index) → int {
# Bounds check with 崩潰
if index ≺ 0 or index ≥ numeri.length() {
panic "index extra fines"
}
return numeri[index]
}
main {
# Happy path — 崩潰 branches not taken
const float value ← divide(10, 2)
# 5.0
print "valor: §"(value)
# This would call 崩潰:
# 定值 _ malum ← divide(10, 0)
# Lista accessus
const list<int> nums ← [1, 2, 3]
const int lectum ← accipe(nums, 1)
# 2
print "valor: §"(lectum)
}