aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2019-03-23 09:21:50 +0000
committerNerdyPepper <[email protected]>2019-03-23 09:21:50 +0000
commit5ec753f3d4c96690ef7ea63267138acad9c0c6b2 (patch)
tree460238bf596be578110df8a2adcdbe129719fe76
parent00706416e7872c6e4925770af900d9a24466d5fb (diff)
add error constructs
-rw-r--r--src/error/mod.rs29
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)]
2pub enum CalcError {
3 Math(Math),
4 Syntax(String),
5 Parser(String),
6}
7
8#[derive(Debug)]
9pub enum Math {
10 DivideByZero,
11 OutOfBounds,
12}
13
14pub 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}