diff --git a/pydu/exception.py b/pydu/exception.py new file mode 100644 index 0000000..49e917b --- /dev/null +++ b/pydu/exception.py @@ -0,0 +1,9 @@ +from contextlib import contextmanager + + +@contextmanager +def ignore(*exceptions): + try: + yield + except exceptions: + pass diff --git a/tests/test_exception.py b/tests/test_exception.py new file mode 100644 index 0000000..6f30aca --- /dev/null +++ b/tests/test_exception.py @@ -0,0 +1,7 @@ +from pydu.exception import ignore + + +def test_ignore(): + with ignore(ValueError, AttributeError): + int('abc') + int.no_exists_func()