ตาย
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH 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)
}