Enum ExecutionError

Source
pub enum ExecutionError {
Show 19 variants StackUnderflow, StackOverflow, TypeError(String), RuntimeError(String), MemoryError(String), InvalidInstruction(String), FunctionError(String), VariableError(String), HeapError(String), ControlFlowError(String), BuiltinError(String), DivisionByZero, InvalidIndex(usize), PropertyNotFound(String), MethodNotFound(String), InvalidArgumentCount { expected: usize, received: usize, }, RecursionLimitExceeded(usize), ExecutionTimeout, UnsupportedOperation(String),
}
Expand description

Represents all possible errors that can occur during VM execution

This enum provides a comprehensive set of error types covering all aspects of virtual machine operation.

Variants§

§

StackUnderflow

Stack is empty when trying to pop a value

§

StackOverflow

Stack is full when trying to push a value

§

TypeError(String)

Invalid type conversion or operation

§

RuntimeError(String)

General runtime execution error

§

MemoryError(String)

Invalid memory access or allocation failure

§

InvalidInstruction(String)

Invalid instruction or bytecode

§

FunctionError(String)

Function call or return error

§

VariableError(String)

Variable access or assignment error

§

HeapError(String)

Heap allocation or garbage collection error

§

ControlFlowError(String)

Control flow error (invalid jumps, etc.)

§

BuiltinError(String)

Built-in function error

§

DivisionByZero

Division by zero

§

InvalidIndex(usize)

Invalid array index

§

PropertyNotFound(String)

Property not found on object

§

MethodNotFound(String)

Method not found on object

§

InvalidArgumentCount

Invalid argument count for function call

Fields

§expected: usize
§received: usize
§

RecursionLimitExceeded(usize)

Recursion limit exceeded

§

ExecutionTimeout

Timeout during execution

§

UnsupportedOperation(String)

Unsupported operation

Implementations§

Source§

impl ExecutionError

Source

pub fn new_type_error(message: impl Into<String>) -> Self

Creates a new type error with the given message

§Arguments
  • message - The error message
§Returns
  • A new ExecutionError::TypeError
§Examples
let error = ExecutionError::new_type_error("Cannot add string and number");
assert!(matches!(error, ExecutionError::TypeError(_)));
Source

pub fn new_runtime_error(message: impl Into<String>) -> Self

Creates a new runtime error with the given message

§Arguments
  • message - The error message
§Returns
  • A new ExecutionError::RuntimeError
§Examples
let error = ExecutionError::new_runtime_error("Function execution failed");
assert!(matches!(error, ExecutionError::RuntimeError(_)));
Source

pub fn new_memory_error(message: impl Into<String>) -> Self

Creates a new memory error with the given message

§Arguments
  • message - The error message
§Returns
  • A new ExecutionError::MemoryError
§Examples
let error = ExecutionError::new_memory_error("Heap allocation failed");
assert!(matches!(error, ExecutionError::MemoryError(_)));
Source

pub fn new_function_error(message: impl Into<String>) -> Self

Creates a new function error with the given message

§Arguments
  • message - The error message
§Returns
  • A new ExecutionError::FunctionError
§Examples
let error = ExecutionError::new_function_error("Invalid function call");
assert!(matches!(error, ExecutionError::FunctionError(_)));
Source

pub fn new_variable_error(message: impl Into<String>) -> Self

Creates a new variable error with the given message

§Arguments
  • message - The error message
§Returns
  • A new ExecutionError::VariableError
§Examples
let error = ExecutionError::new_variable_error("Variable not defined");
assert!(matches!(error, ExecutionError::VariableError(_)));
Source

pub fn new_heap_error(message: impl Into<String>) -> Self

Creates a new heap error with the given message

§Arguments
  • message - The error message
§Returns
  • A new ExecutionError::HeapError
§Examples
let error = ExecutionError::new_heap_error("Garbage collection failed");
assert!(matches!(error, ExecutionError::HeapError(_)));
Source

pub fn new_control_flow_error(message: impl Into<String>) -> Self

Creates a new control flow error with the given message

§Arguments
  • message - The error message
§Returns
  • A new ExecutionError::ControlFlowError
§Examples
let error = ExecutionError::new_control_flow_error("Invalid jump target");
assert!(matches!(error, ExecutionError::ControlFlowError(_)));
Source

pub fn new_builtin_error(message: impl Into<String>) -> Self

Creates a new built-in error with the given message

§Arguments
  • message - The error message
§Returns
  • A new ExecutionError::BuiltinError
§Examples
let error = ExecutionError::new_builtin_error("Console not available");
assert!(matches!(error, ExecutionError::BuiltinError(_)));
Source

pub fn new_unsupported_operation(message: impl Into<String>) -> Self

Creates a new unsupported operation error with the given message

§Arguments
  • message - The error message
§Returns
  • A new ExecutionError::UnsupportedOperation
§Examples
let error = ExecutionError::new_unsupported_operation("BigInt operations");
assert!(matches!(error, ExecutionError::UnsupportedOperation(_)));
Source

pub fn is_recoverable(&self) -> bool

Checks if this error is recoverable

Some errors can be recovered from automatically, while others require manual intervention or indicate a serious problem.

§Returns
  • true if the error is recoverable
  • false if the error requires manual intervention
§Examples
let stack_error = ExecutionError::StackUnderflow;
assert!(stack_error.is_recoverable());

let type_error = ExecutionError::TypeError("Invalid operation".to_string());
assert!(!type_error.is_recoverable());
Source

pub fn is_fatal(&self) -> bool

Checks if this error is fatal

Fatal errors cannot be recovered from and typically indicate a serious problem with the program or VM state.

§Returns
  • true if the error is fatal
  • false if the error is not fatal
§Examples
let memory_error = ExecutionError::MemoryError("Heap corruption".to_string());
assert!(memory_error.is_fatal());

let stack_error = ExecutionError::StackUnderflow;
assert!(!stack_error.is_fatal());
Source

pub fn get_user_message(&self) -> String

Gets a user-friendly error message

Returns a formatted error message suitable for display to users.

§Returns
  • A formatted error message string
§Examples
let error = ExecutionError::TypeError("Cannot add string and number".to_string());
let message = error.get_user_message();
assert!(message.contains("Type error"));
Source

pub fn get_debug_message(&self) -> String

Gets a debug error message

Returns a detailed error message suitable for debugging and development.

§Returns
  • A detailed debug message string
§Examples
let error = ExecutionError::TypeError("Cannot add string and number".to_string());
let debug_msg = error.get_debug_message();
assert!(debug_msg.contains("TypeError"));

Trait Implementations§

Source§

impl Clone for ExecutionError

Source§

fn clone(&self) -> ExecutionError

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExecutionError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ExecutionError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ExecutionError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.