Skip to content

Commit

Permalink
Integrated Basic Error Handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
PranavVerma-droid committed Oct 13, 2024
1 parent 69456a7 commit 2264715
Show file tree
Hide file tree
Showing 5 changed files with 556 additions and 494 deletions.
32 changes: 32 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::fmt;

#[derive(Debug)]
pub enum Error {
SyntaxError(String),
IndexOutOfBounds(String),
VariableNotDeclared(String),
VariableAlreadyDeclared(String),
TypeError(String),
UnsupportedOperation(String),
BreakOutsideLoop,
ContinueOutsideLoop,
//UnknownError(String),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::SyntaxError(msg) => write!(f, "SyntaxError: {}", msg),
Error::IndexOutOfBounds(msg) => write!(f, "IndexOutOfBounds: {}", msg),
Error::VariableNotDeclared(msg) => write!(f, "VariableNotDeclared: {}", msg),
Error::VariableAlreadyDeclared(msg) => write!(f, "VariableAlreadyDeclared: {}", msg),
Error::TypeError(msg) => write!(f, "TypeError: {}", msg),
Error::UnsupportedOperation(msg) => write!(f, "UnsupportedOperation: {}", msg),
Error::BreakOutsideLoop => write!(f, "Break statement outside of loop"),
Error::ContinueOutsideLoop => write!(f, "Continue statement outside of loop"),
// Error::UnknownError(msg) => write!(f, "UnknownError: {}", msg),
}
}
}

impl std::error::Error for Error {}
Loading

0 comments on commit 2264715

Please sign in to comment.