From 5ec753f3d4c96690ef7ea63267138acad9c0c6b2 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Sat, 23 Mar 2019 14:51:50 +0530 Subject: add error constructs --- src/error/mod.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/error/mod.rs (limited to 'src') diff --git a/src/error/mod.rs b/src/error/mod.rs new file mode 100644 index 0000000..14153fe --- /dev/null +++ b/src/error/mod.rs @@ -0,0 +1,29 @@ +#[derive(Debug)] +pub enum CalcError { + Math(Math), + Syntax(String), + Parser(String), +} + +#[derive(Debug)] +pub enum Math { + DivideByZero, + OutOfBounds, +} + +pub fn handler(e: CalcError) { + match e { + CalcError::Math(math_err) => { + match math_err { + Math::DivideByZero => println!("Math Error: Divide by zero error!"), + Math::OutOfBounds => println!("Domain Error: Out of bounds!") + } + }, + CalcError::Syntax(details) => { + println!("Syntax Error: {}", details); + }, + CalcError::Parser(details) => { + println!("Parser Error: {}", details); + } + } +} -- cgit v1.2.3