Skip to content

Instantly share code, notes, and snippets.

@wakhub
Last active August 29, 2015 14:08
Show Gist options
  • Save wakhub/ac6d9b33876522dc9ed4 to your computer and use it in GitHub Desktop.
Save wakhub/ac6d9b33876522dc9ed4 to your computer and use it in GitHub Desktop.
from functools import wraps
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def suppress_error(f):
""" Suppress error
:param function f:
:rtype: function
"""
@wraps(f)
def decorated_function(*args, **kwargs):
try:
return f(*args, **kwargs)
except (Exception) as e:
logger.warn("Suppress %s", e, exc_info=True)
return decorated_function
def test():
@suppress_error
def f():
raise Exception('[To be suppressed]')
f()
logger.debug('--- This code is not blocked ---')
if __name__ == '__main__':
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment