Skip to content

Instantly share code, notes, and snippets.

@Allwin12
Created April 18, 2022 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Allwin12/1a2004f2db4021ca61914dd42534bcfe to your computer and use it in GitHub Desktop.
Save Allwin12/1a2004f2db4021ca61914dd42534bcfe to your computer and use it in GitHub Desktop.
# 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