Skip to content

Instantly share code, notes, and snippets.

@johnmanjiro13
Last active October 26, 2018 14:03
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 johnmanjiro13/d668ccc9bd95d240cabc7f2bcbc863a5 to your computer and use it in GitHub Desktop.
Save johnmanjiro13/d668ccc9bd95d240cabc7f2bcbc863a5 to your computer and use it in GitHub Desktop.
try_except decorator
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