@extensionclassmethod(Observable)
def catch_exception(cls, *args):
    """Continues an observable sequence that is terminated by an
    exception with the next observable sequence.

    1 - res = Observable.catch_exception(xs, ys, zs)
    2 - res = Observable.catch_exception([xs, ys, zs])

    Returns an observable sequence containing elements from consecutive
    source sequences until a source sequence terminates successfully.
    """

    if isinstance(args[0], list) or isinstance(args[0], Enumerable):
        sources = args[0]
    else:
        sources = list(args)

    #return Enumerable.catch_exception(Enumerable.for_each(sources))

    def subscribe(observer):
        e = iter(sources)
        is_disposed = [False]
        last_exception = [None]
        subscription = SerialDisposable()

        def action(action1, state=None):
            def on_error(exn):
                last_exception[0] = exn
                action1()

            if is_disposed[0]:
                return
            try:
                current = next(e)
            except __HOLE__:
                if last_exception[0]:
                    observer.on_error(last_exception[0])
                else:
                    observer.on_completed()
            except Exception as ex:
                observer.on_error(ex)
            else:
                d = SingleAssignmentDisposable()
                subscription.disposable = d

                d.disposable = current.subscribe(
                    observer.on_next,
                    on_error,
                    observer.on_completed
                )

        cancelable = immediate_scheduler.schedule_recursive(action)

        def dispose():
            is_disposed[0] = True
        return CompositeDisposable(subscription, cancelable, Disposable(dispose))
    return AnonymousObservable(subscribe)
dataset/ETHPy150Open ReactiveX/RxPY/rx/linq/observable/catch.py/catch_exception