Last active
October 26, 2018 14:03
-
-
Save johnmanjiro13/d668ccc9bd95d240cabc7f2bcbc863a5 to your computer and use it in GitHub Desktop.
try_except decorator
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
from functools import wraps | |
def try_except(exreturn_value=None): | |
def _except_decorator(func): | |
@wraps(func) | |
def _except_internal(*args, **kwargs): | |
try: | |
return func(*args, **kwargs) | |
except Exception: | |
return exreturn_value | |
return _except_internal | |
return _except_decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment