class documentation

class ExceptionTrap: (source)

View In Hierarchy

A context manager that will catch certain exceptions and provide an indication they occurred. >>> with ExceptionTrap() as trap: ... raise Exception() >>> bool(trap) True >>> with ExceptionTrap() as trap: ... pass >>> bool(trap) False >>> with ExceptionTrap(ValueError) as trap: ... raise ValueError("1 + 1 is not 3") >>> bool(trap) True >>> trap.value ValueError('1 + 1 is not 3') >>> trap.tb <traceback object at ...> >>> with ExceptionTrap(ValueError) as trap: ... raise Exception() Traceback (most recent call last): ... Exception >>> bool(trap) False

Method __bool__ Undocumented
Method __enter__ Undocumented
Method __exit__ Undocumented
Method __init__ Undocumented
Method passes Wrap func and replace the result with the truth value of the trap (True if no exception).
Method raises Wrap func and replace the result with the truth value of the trap (True if an exception occurred).
Instance Variable exc_info Undocumented
Instance Variable exceptions Undocumented
Property tb Undocumented
Property type Undocumented
Property value Undocumented
def __bool__(self): (source)

Undocumented

def __enter__(self): (source)

Undocumented

def __exit__(self, *exc_info): (source)

Undocumented

def __init__(self, exceptions=(Exception)): (source)

Undocumented

def passes(self, func): (source)

Wrap func and replace the result with the truth value of the trap (True if no exception). First, give the decorator an alias to support Python 3.8 Syntax. >>> passes = ExceptionTrap(ValueError).passes Now decorate a function that always fails. >>> @passes ... def fail(): ... raise ValueError('failed') >>> fail() False

def raises(self, func, *, _test=bool): (source)

Wrap func and replace the result with the truth value of the trap (True if an exception occurred). First, give the decorator an alias to support Python 3.8 Syntax. >>> raises = ExceptionTrap(ValueError).raises Now decorate a function that always fails. >>> @raises ... def fail(): ... raise ValueError('failed') >>> fail() True

exc_info = (source)

Undocumented

exceptions = (source)

Undocumented

Undocumented

Undocumented

Undocumented