From 87d90c394fb661fd0bb38e652e1d7fdb5c261325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Thu, 23 Mar 2023 20:04:21 +0100 Subject: [PATCH] :sparkles: Added MachineError struct --- src/simulator/error.rs | 27 +++++++++++++++++++++++++++ src/simulator/mod.rs | 1 + 2 files changed, 28 insertions(+) create mode 100644 src/simulator/error.rs diff --git a/src/simulator/error.rs b/src/simulator/error.rs new file mode 100644 index 0000000..42db367 --- /dev/null +++ b/src/simulator/error.rs @@ -0,0 +1,27 @@ +use std::fmt; + +/// Machine Error +/// This error serves as a specific exception handler for the Machine struct +#[derive(Debug, Clone)] +pub struct MachineError { + /// The error message + message: String +} + +impl MachineError { + + pub fn new(message: &str) -> MachineError { + MachineError { + message: message.to_string() + } + } + +} + +impl fmt::Display for MachineError { + + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Machine error: {}", &self.message) + } + +} \ No newline at end of file diff --git a/src/simulator/mod.rs b/src/simulator/mod.rs index 8626048..e13df71 100644 --- a/src/simulator/mod.rs +++ b/src/simulator/mod.rs @@ -1,4 +1,5 @@ pub mod machine; +pub mod error; pub mod decode; pub mod print; pub mod mem_cmp;