from contextlib import contextmanager
@contextmanager
def catch(*exceptions, **kwargs):
try:
yield kwargs.get("default", None)
except exceptions or Exception:
print kwargs
#Example
with catch(**{'Variable not found' : 'Variable_name' }) as _:
some_variable = function_to_get_something(bar)
Last active
August 29, 2015 14:24
-
-
Save hellpanderrr/2bdcb13baea433ec8376 to your computer and use it in GitHub Desktop.
Python handling exception in a context manager
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment