-
Notifications
You must be signed in to change notification settings - Fork 43
/
personal_errors.py
53 lines (39 loc) · 1.35 KB
/
personal_errors.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
This is a personalized class for managing exceptions in project.
This is also responsible for writing error messages inside log file.
I decided to create a general class and then use subclasses for the sake of decoupling
"""
import logging
from logger import TimeHandler
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(TimeHandler().handler)
class Error(Exception):
"""Base class for exceptions in this module."""
def __init__(self, message):
self.message = message
logger.error(message)
def __str__(self):
return 'Some error occurred: \n{msg}\nAborting...'.format(msg=self.message)
class InputError(Error):
"""Exception raised for errors in the input.
Attributes:
expression -- input expression in which the error occurred
message -- explanation of the error
"""
def __init__(self, message):
super().__init__(message)
class OutputError(Error):
"""Exception raised for errors in the output.
Attributes:
expression -- input expression in which the error occurred
message -- explanation of the error
"""
def __init__(self, message):
super().__init__(message)
class APIError(Error):
"""
Exception raised for general API call exceptions
"""
def __init__(self, message):
super().__init__(message)