Skip to content
richardszalay edited this page May 20, 2011 · 6 revisions

Runs a specific sequence when an error occurs, and prevents the original error message from being emitted

static function catchErrors(sources : Array.< IObservable.<T> >) : IObservable.<T>

Remarks

Subscribes to the first sequence in sources. If an error occurs, the current sequence is unsubscribed from and the next sequence in sources.

The returned sequence completes if the current sequence in sources completes

The returned sequence errors if the last sequence in sources errors.

Marble Diagrams

ws,xs,ys = sources
zs       = output

ws ──o─────o─────x
     │     │     │
xs   │     │     └─o─o─x
     │     │       │ │ │
ys   │     │       │ │ └─o─o─/
     │     │       │ │   │ │ │
zs ──o─────o───────o─o───o─o─/

ws ──o─────o─────x
     │     │     │
xs   │     │     └─o─o─x
     │     │       │ │ │
ys   │     │       │ │ └─o─o─x
     │     │       │ │   │ │ │
zs ──o─────o───────o─o───o─o─x

Scheduling

Unless specified, Scheduler.synchronous will be used to schedule the subscription to each source, including the first.

Return Value

IObservable.<T>

Examples

var sourceA : IObservable = Observable.value(1)
    .concat(int, Observable.error(new Error("Error 1"));

var sourceB : IObservable = Observable.value(2)
    .concat(int, Observable.error(new Error("Error 2"));

var sourceC : IObservable = Observable.value(3);

Observable.catchErrors([sourceA, sourceB, sourceC])
    .subscribe(
        function(x:int) : void { trace(x); },
        function() : void { trace("Completed"); },
        function(e:Error) : void { trace("Error: " + e.message); }
    );

    // Trace output is:
    // 1
    // 2
    // 3
    // Completed
var sourceA : IObservable = Observable.value(1)
    .concat(int, Observable.error(new Error("Error 1"));

var sourceB : IObservable = Observable.value(2)
    .concat(int, Observable.error(new Error("Error 2"));

var sourceC : IObservable = Observable.value(3)
    .concat(int, Observable.error(new Error("Error 3"));

Observable.catchErrors([sourceA, sourceB, sourceC])
    .subscribe(
        function(x:int) : void { trace(x); },
        function() : void { trace("Completed"); },
        function(e:Error) : void { trace("Error: " + e.message); }
    );

    // Trace output is:
    // 1
    // 2
    // 3
    // Error: Error 3
Clone this wiki locally