schip8/errors.rs
1use thiserror::Error;
2
3/// The error types used by the interpreter
4#[derive(Error, Debug)]
5pub enum ChipError {
6 /// This error occurs when attempting to access out of bounds memory
7 #[error("The address {address:?} is out of bounds. The limits are: (0, {limit:?})")]
8 AddressOutOfBounds { address: usize, limit: usize },
9
10 /// Thrown by the CPU when attempting to pop() from an empty stack
11 #[error("Attempted to remove item from an empty stack")]
12 StackUnderflow(),
13
14 /// Thrown by the CPU attempting to push() to a full stack
15 #[error("Stack size limit exceeded. Maximum size: {0}")]
16 StackOverflow(usize),
17
18 /// Thrown by the CPU when attempting to execute an unknown opcode
19 #[error("The opcode {:#06x} is not implemented", .opcode)]
20 OpcodeNotImplemented { opcode: u16 },
21}