CatchException

Definition

class broqer.op.CatchException(*exceptions)[source]

Catching exceptions of following operators in the pipelines

Parameters:exceptions – Exception classes to be catched

Usage

>>> from broqer import Subject, op
>>> s = Subject()

Example with exception:

>>> disposable = s | op.Map(lambda s:1/s) | op.Sink(print)
>>> s.emit(1)
1.0
>>> s.emit(0)
Traceback (most recent call last):
...
ZeroDivisionError: division by zero
>>> disposable.dispose()

Now with catch_exception:

>>> excp = ZeroDivisionError
>>> s | op.CatchException(excp) | op.Map(lambda s:1/s) | op.Sink(print)
<...>
>>> s.emit(1)
1.0
>>> s.emit(0) # will cause a exception but will be catched