panic
panic(msg: string)
Prints file:line: panic: <msg> to standard error and aborts the process with exit code 1. It turns "something went wrong" into a clear, located message a non-expert can act on — the opposite of a raw segfault or a silent wrong result. Use it for the unrecoverable case: a corrupt asset, a broken invariant, a branch that should be impossible. The source location is baked in at compile time, so the message always points at the exact call. For a guarded check that only aborts when a condition fails, use assert.
Recoverable failures — a missing save, a bad network packet — are a different story: those should be values a game can fall back from rather than a panic. That value-carrying path is try/else over a result; panic covers the unrecoverable programmer-bug half.
Parameters
msga message describing what went wrong (a string)Example
program Demo {
function pick(options: int, n: int) -> int {
if n < 0 { panic("choice index is negative") }
if n >= options { panic("choice index out of range") }
return n
}
entry {
print(pick(3, 1)) # 1
print(pick(3, 9)) # aborts: Demo.ludic:6: panic: choice index out of range
}
}