Skip to content

Commit

Permalink
New CustomError class + error handling + minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Jul 5, 2021
1 parent 4dc9ec4 commit 943f10a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Apple:
"""
The apple in the Snake game.
"""

def __init__(self, asset='o'):
"""
Creates a new empty apple.
Expand Down
31 changes: 31 additions & 0 deletions src/errors.py
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

0 comments on commit 943f10a

Please sign in to comment.