Landin library reference source

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

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 | unreachable

core/panic/panic.ldn:15

The 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: atom

core/panic/panic.ldn:9

A checked conversion cannot represent the source value in its target type.

out_of_range atom

public out_of_range: atom

core/panic/panic.ldn:5

A 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: atom

core/panic/panic.ldn:7

A checked arithmetic operation cannot represent its result.

unreachable atom

public unreachable: atom

core/panic/panic.ldn:11

Execution reached a path declared unreachable.