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
30
31
32
33
34
35
36
37
use std::error::Error;
use std::fmt;
use std::fmt::{Display, Formatter};

#[derive(Debug)]
pub enum ExceptionType {
    Static,
    Runtime,
}

impl Display for ExceptionType {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            ExceptionType::Runtime => write!(f, "Runtime"),
            ExceptionType::Static => write!(f, "Syntax"),
        }
    }
}

#[derive(Debug)]
pub struct Exception {
    pub exception_type: ExceptionType,
    pub name: String,
    pub message: String,
}

impl Display for Exception {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "[{}] {}: {}",
            self.exception_type, self.name, self.message
        )
    }
}

impl Error for Exception {}