-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
58 lines (41 loc) · 1.5 KB
/
exceptions.py
File metadata and controls
58 lines (41 loc) · 1.5 KB
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
54
55
56
57
58
"""
This file contains the custom exceptions that are raised in the application.
"""
# Show the custom exception that is raised when the user tries to access a non-existent page.
class PageNotFound(Exception):
"""
This class is used to raise a PageNotFound exception when the user tries to access a page that is not allowed.
"""
def __init__(self, message):
self.message = message
super().__init__(self.message)
# Show the custom exception that is raised when the user tries to access a page that is not allowed.
class ForbiddenPage(Exception):
"""
This class is used to raise a ForbiddenPage exception when the user tries to access a page that is not allowed.
"""
def __init__(self, message):
self.message = message
super().__init__(self.message)
# Show the custom exception that is raised when the user tries to access a page that is not allowed.
class InvalidInput(Exception):
"""
This class is used to raise an InvalidInput exception when the user tries to access a page that is not allowed.
"""
def __init__(self, message):
self.message = message
super().__init__(self.message)
# Show a try-except block to catch the custom exceptions.
try:
raise PageNotFound("Page not found")
except PageNotFound as e:
print(e)
try:
raise ForbiddenPage("Forbidden page")
except ForbiddenPage as e:
print(e)
try:
raise InvalidInput("Invalid input")
except InvalidInput as e:
print(e)
# End of exceptions.py