core/panic
Shared: available on every enabled target.
The four compiler panic atoms and their shared panic-kind domain.
Checked range, arithmetic and conversion faults, and an unreachable path, use these atoms. An entry-module panic handler has the language-specified nonreturning signature. A panic is distinct from a recoverable allocator or I/O error.
Items
- panic_kind type
- bad_conversion atom
- out_of_range atom
- overflow atom
- unreachable atom
Executable example
This complete program is maintained in the repository runtime tests. View source.
import core/panic exercise: () -> (ok: bool) = ok = false kind: panic.panic_kind = panic.bad_conversion ok = kind == panic.bad_conversion and kind <> panic.overflow end exercise public main: () -> (code: i32) = code = 1 ok := exercise() if ok then code = 42 end if end main
panic_kind type
public panic_kind: type = out_of_range | overflow | bad_conversion | unreachableThe compiler's four panic atoms. A program may supply the specified nonreturning panic handler; these failures are not allocator error returns.
bad_conversion atom
public bad_conversion: atomA checked conversion cannot represent the source value in its target type.
out_of_range atom
public out_of_range: atomA checked index or range is outside its valid extent.
Compiler-check reasons. The representation is the ordinary nonzero atom carrier; callers compare identities, never assumed integer codes.
overflow atom
public overflow: atomA checked arithmetic operation cannot represent its result.
unreachable atom
public unreachable: atomExecution reached a path declared unreachable.