Skip to content

Instantly share code, notes, and snippets.

@cassc
Created September 16, 2021 01:41
Show Gist options
  • Save cassc/a53af3ad2549c771ead533f56a0268e7 to your computer and use it in GitHub Desktop.
Save cassc/a53af3ad2549c771ead533f56a0268e7 to your computer and use it in GitHub Desktop.
Python decorator sample usage
def ignore_error(func):
def myfunc(*args, **kwargs):
try:
func(*args, **kwargs)
except Exception:
print('Error ignored')
traceback.print_exc(file=sys.stdout)
return myfunc
@ignore_error
def divide(n):
print(f'8 / {n} = {8.0/n} ')
divide(8)
divide(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment