Bases: object
Bases: object
A context manager that prevents some exceptions from being raised.
For backwards compatibility, these objects can also be called with the exception value as an argument - any non-matching exception will be re-raised from this call. We attempt but cannot guarantee to keep the same traceback; the context manager method is preferred for this reason except in cases where the ignored exception affects control flow.
Use this class as a decorator for a function that returns whether a given exception should be ignored. e.g.
>>> @ExceptionFilter
>>> def ignore_assertions(ex):
... return isinstance(ex, AssertionError)
and then use it as a context manager:
>>> with ignore_assertions:
... assert False
or call it:
>>> try:
... assert False
... except Exception as ex:
... ignore_assertions(ex)