-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New CustomError class + error handling + minor changes.
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class CustomError(Exception): | ||
pass | ||
|
||
|
||
# class CustomError(Exception): | ||
# """Exception raised for errors in the input salary. | ||
# | ||
# Attributes: | ||
# salary -- input salary which caused the error | ||
# message -- explanation of the error | ||
# """ | ||
# | ||
# def __init__(self, salary, message="Salary is not in (5000, 15000) range"): | ||
# self.salary = salary | ||
# self.message = message | ||
# super().__init__(self.message) | ||
# | ||
# def __str__(self): | ||
# return f'{self.salary} -> {self.message}' | ||
|
||
def error_handler(func): | ||
def wrapper(*args, **kwargs): | ||
try: | ||
res = func(*args, **kwargs) | ||
return res | ||
except CustomError as ce: | ||
print(ce) | ||
except KeyboardInterrupt: | ||
pass | ||
|
||
return wrapper |