Fatal Errors

A fatal error aborts the program on an unrecoverable condition rather than returning an error to the caller. Fatal errors are reserved for bugs and invariant violations — situations the program is not expected to handle at runtime.

You can trigger one explicitly with Panic from the Core package, which prints a diagnostic message and the call-site location to standard error and exits with code 1:

import Core::Panic;

Panic("unreachable: unknown variant");

Several documented operations also fail fatally:

  • Integer overflow in debug builds raises a fatal error; release builds wrap instead (see Signed Integer overflow behaviour).
  • Narrowing character casts raise a fatal error when the value is out of range; use as? to get null instead (see Character Types).
  • Casting NaN or Inf to an integer raises a fatal error in debug builds (see Floating-Point Types).

For conditions a caller is expected to recover from, return a Result instead.

See Also

  • The Result Type — the recoverable-error alternative
  • Panic — the standard-library function that triggers a fatal error
  • Intrinsic Constants — the #source.file/#source.line values reported at the call site