-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise_3.py
35 lines (26 loc) · 1.05 KB
/
Exercise_3.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
import logging
# Custom Exception
class ValueTooHighError(Exception):
def __init__(self, message="Value is too high! Must be less than or equal to 100."):
self.message = message
super().__init__(self.message)
# Configure logging
logging.basicConfig(filename='custom_exception_log.txt', level=logging.ERROR,
format='%(asctime)s - %(levelname)s - %(message)s')
def check_value():
try:
num = float(input("Enter a number: "))
if num > 100:
raise ValueTooHighError(f"Input value {num} exceeds the limit of 100.")
print(f"Your number {num} is valid!")
except ValueTooHighError as e:
logging.error(e)
print(e)
except ValueError:
logging.error("Invalid input. Non-numeric value entered.")
print("Error: Please enter a valid numeric value.")
except Exception as e:
logging.error(f"An unexpected error occurred: {e}")
print(f"An unexpected error occurred: {e}")
if __name__ == '__main__':
check_value()