diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..ec2b555 --- /dev/null +++ b/src/error.rs | |||
@@ -0,0 +1,29 @@ | |||
1 | /* Copyright (C) 2019 Akshay Oppiliappan <[email protected]> | ||
2 | * Refer to LICENCE for more information. | ||
3 | * */ | ||
4 | |||
5 | #[derive(Debug)] | ||
6 | pub enum CalcError { | ||
7 | Math(Math), | ||
8 | Syntax(String), | ||
9 | Parser(String), | ||
10 | } | ||
11 | |||
12 | #[derive(Debug)] | ||
13 | pub enum Math { | ||
14 | DivideByZero, | ||
15 | OutOfBounds, | ||
16 | UnknownBase, | ||
17 | } | ||
18 | |||
19 | pub fn handler(e: CalcError) -> String { | ||
20 | match e { | ||
21 | CalcError::Math(math_err) => match math_err { | ||
22 | Math::DivideByZero => "Math Error: Divide by zero error!".to_string(), | ||
23 | Math::OutOfBounds => "Domain Error: Out of bounds!".to_string(), | ||
24 | Math::UnknownBase => "Base too large! Accepted ranges: 0 - 36".to_string(), | ||
25 | }, | ||
26 | CalcError::Syntax(details) => format!("Syntax Error: {}", details), | ||
27 | CalcError::Parser(details) => format!("Parser Error: {}", details), | ||
28 | } | ||
29 | } | ||