1class SalaryNotInRangeError(Exception):
2 """Exception raised for errors in the input salary.
3
4 Attributes:
5 salary -- input salary which caused the error
6 message -- explanation of the error
7 """
8
9 def __init__(self, salary, message="Salary is not in (5000, 15000) range"):
10 self.salary = salary
11 self.message = message
12 super().__init__(self.message)
13
14 def __str__(self):
15 return f'{self.salary} -> {self.message}'
16
17
18salary = int(input("Enter salary amount: "))
19if not 5000 < salary < 15000:
20 raise SalaryNotInRangeError(salary)
1class UnderAge(Exception):
2 pass
3
4def verify_age(age):
5 if int(age) < 18:
6 raise UnderAge
7 else:
8 print('Age: '+str(age))
9
10# main program
11verify_age(23) # won't raise exception
12verify_age(17) # will raise exception