diff options
Diffstat (limited to 'src/error')
-rw-r--r-- | src/error/mod.rs | 29 |
1 files changed, 29 insertions, 0 deletions
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 @@ | |||
1 | #[derive(Debug)] | ||
2 | pub enum CalcError { | ||
3 | Math(Math), | ||
4 | Syntax(String), | ||
5 | Parser(String), | ||
6 | } | ||
7 | |||
8 | #[derive(Debug)] | ||
9 | pub enum Math { | ||
10 | DivideByZero, | ||
11 | OutOfBounds, | ||
12 | } | ||
13 | |||
14 | pub fn handler(e: CalcError) { | ||
15 | match e { | ||
16 | CalcError::Math(math_err) => { | ||
17 | match math_err { | ||
18 | Math::DivideByZero => println!("Math Error: Divide by zero error!"), | ||
19 | Math::OutOfBounds => println!("Domain Error: Out of bounds!") | ||
20 | } | ||
21 | }, | ||
22 | CalcError::Syntax(details) => { | ||
23 | println!("Syntax Error: {}", details); | ||
24 | }, | ||
25 | CalcError::Parser(details) => { | ||
26 | println!("Parser Error: {}", details); | ||
27 | } | ||
28 | } | ||
29 | } | ||