#[non_exhaustive]pub enum ErrorKind {
Show 22 variants
ArithOverflow,
DivByZero,
ShiftOutOfRange,
InvalidConversion,
InvalidChar,
NegativeExponent,
TypeError,
NullReference,
IndexOutOfBounds,
KeyNotFound,
UndefinedProperty,
StackOverflow,
OutOfMemory,
OutOfFuel,
InvalidStrIndex,
Unreachable,
InvalidCoroState,
CannotSuspend,
NoScheduler,
CloseIgnored,
ArgumentError,
NoMatch,
}Expand description
A runtime error kind with its stable code.
Codes E0001–E0099 are defined by specs/OPS.md §6 for arithmetic
and conversions, E0100–E0199 by LSB for the other instructions, and
E0200–E0299 by HIR for its own forms (specs/HIR.md §8.10). Every
execution tier raises the same kind for the same fault.
Inst::ErrCode reads the numeric code back from
a caught error value, and Inst::Raise raises any
catchable kind from bytecode (how a code generator raises HIR’s
NoMatch).
§Examples
use bytecode_lang::ErrorKind;
assert_eq!(ErrorKind::DivByZero.code(), 2);
assert_eq!(ErrorKind::DivByZero.to_string(), "E0002 DivByZero");
assert_eq!(ErrorKind::from_code(102), Some(ErrorKind::IndexOutOfBounds));
assert!(!ErrorKind::OutOfFuel.is_catchable());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
ArithOverflow
E0001: an integer result does not fit under overflow = error.
DivByZero
E0002: integer division by zero under div_zero = error.
ShiftOutOfRange
E0003: a shift amount out of range under shift = error.
InvalidConversion
E0004: NaN or an out-of-range float converted under float_to_int = error.
InvalidChar
E0005: char_from_u32 on a value that is not a Unicode scalar value.
NegativeExponent
E0006: integer pow with a negative exponent under any overflow
policy but promote (OPS v2).
TypeError
E0100: a dynamic operation on kinds it does not support, a failed
cast or from_dyn, or an argument of a dynamic call that does not
convert to its parameter’s type.
NullReference
E0101: a heap instruction on a nil reference.
IndexOutOfBounds
E0102: an array, string, or length operand out of range.
KeyNotFound
E0103: map_get (or dget_index on a map) of an absent key.
UndefinedProperty
E0104: get_prop/set_prop of a name the object does not have.
StackOverflow
E0105: the call depth limit was reached.
OutOfMemory
E0106: an allocation failed. Always a trap.
OutOfFuel
E0107: the run’s fuel budget is spent. Always a trap.
InvalidStrIndex
E0108: a UTF-8 str_slice boundary inside a character.
Unreachable
E0109: unreachable was executed. Always a trap.
InvalidCoroState
E0110: a coroutine operation in a state that does not allow it:
resuming one that is running, returned, or failed (a coroutine
resuming itself included), or coro_result before it returned.
CannotSuspend
E0111: yield or await with no coroutine to suspend, or with a
host frame between the instruction and its coroutine.
NoScheduler
E0112: spawn in a module with no spawn hook bound.
CloseIgnored
E0113: a coroutine being closed yielded instead of finishing (Python’s “generator ignored GeneratorExit”).
ArgumentError
E0114: a dynamic call’s arguments do not bind to the callee’s
parameters: too many or too few, an unknown or repeated name, a
positional argument after a named one (see
ParamList::bind).
NoMatch
E0200: a match none of whose arms matches (HIR v3 §8.10; Mox’s
UnhandledMatchError). No instruction raises it by itself: code
generators raise it with Inst::Raise, the
scrutinee as payload.
Implementations§
Source§impl ErrorKind
impl ErrorKind
Sourcepub const fn code(self) -> u32
pub const fn code(self) -> u32
The stable numeric code (2 for E0002).
§Examples
use bytecode_lang::ErrorKind;
assert_eq!(ErrorKind::TypeError.code(), 100);Sourcepub fn from_code(code: u32) -> Option<Self>
pub fn from_code(code: u32) -> Option<Self>
The kind with this numeric code, or None.
§Examples
use bytecode_lang::ErrorKind;
assert_eq!(ErrorKind::from_code(1), Some(ErrorKind::ArithOverflow));
assert_eq!(ErrorKind::from_code(0), None);Sourcepub const fn name(self) -> &'static str
pub const fn name(self) -> &'static str
The kind’s name, as in OPS and LSB.
§Examples
use bytecode_lang::ErrorKind;
assert_eq!(ErrorKind::KeyNotFound.name(), "KeyNotFound");Sourcepub const fn is_catchable(self) -> bool
pub const fn is_catchable(self) -> bool
Whether a try region can catch this kind. Resource exhaustion and
unreachable always abort the run; every other kind is raised as an
error (or aborts, if the instruction’s policy says trap).
§Examples
use bytecode_lang::ErrorKind;
assert!(ErrorKind::KeyNotFound.is_catchable());
assert!(!ErrorKind::Unreachable.is_catchable());