Created
April 18, 2022 19:15
-
-
Save Allwin12/1a2004f2db4021ca61914dd42534bcfe to your computer and use it in GitHub Desktop.
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
# decorator function | |
def exception_handler(func): | |
def wrapper(*args): | |
try: | |
func(*args) | |
except Exception as error: | |
print(error) | |
return wrapper | |
@exception_handler | |
def some_function(): | |
print(2//0) | |
@exception_handler | |
def another_function(): | |
empty_list = [] | |
print(empty_list[0]) | |
some_function() | |
another_function() | |
# output | |
############################################# | |
# integer division or modulo by zero # | |
# list index out of range # | |
############################################# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment