aboutsummaryrefslogtreecommitdiff
path: root/src/error/mod.rs
blob: 14153fea3f264950956535c951bd452763e5b73d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
        }
    }
}