Last active
August 29, 2015 14:08
-
-
Save wakhub/ac6d9b33876522dc9ed4 to your computer and use it in GitHub Desktop.
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 | |
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