Skip to main content

virtual_rust/interpreter/
error.rs

1//! Runtime error type for the interpreter.
2
3use std::fmt;
4
5/// An error produced during interpretation (e.g. type mismatch, undefined variable).
6#[derive(Debug)]
7pub struct RuntimeError {
8    pub message: String,
9}
10
11impl RuntimeError {
12    /// Creates a new `RuntimeError` with the given message.
13    pub fn new(message: impl Into<String>) -> Self {
14        RuntimeError {
15            message: message.into(),
16        }
17    }
18}
19
20impl fmt::Display for RuntimeError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        write!(f, "Runtime error: {}", self.message)
23    }
24}