Created
September 16, 2021 01:41
-
-
Save cassc/a53af3ad2549c771ead533f56a0268e7 to your computer and use it in GitHub Desktop.
Python decorator sample usage
This file contains hidden or 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
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