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

Runs a specific sequence, determined at runtime, when an error occurs

function catchErrorDefered(errorClass : Class, 
    deferFunc : Function) : IObservable.<T>

Where errorClass is the class of error to filter on. Errors not of this class (or a subclass) will not trigger the deferFunc.

Where deferFunc function(error : Error) : IObservable.<T>

Remarks

If an error occurs in the source sequence, deferFunc will be called with the error as an argument. The IObservable return value from deferFunc will then be subscribed to.

The returned sequence completes when the source sequence completes.

The returned sequence errors if deferFunc throws an error or if the sequence returned by deferFunc errors.

Marble Diagrams

f(e) = deferFunc(error)

xs ──o─────o─────x
     │     │     │
     │     │    f(e)
     │     │     └─o─o─/
     │     │       │ │ │
zs ──o─────o───────o─o─/

xs ──o─────o─────x
     │     │     │
     │     │    f(e)
     │     │     └─o─o─x
     │     │       │ │ │
zs ──o─────o───────o─o─x

ws ──o─────o─────/
     │     │     │
     │     │     │
     │     │     │
     │     │     │
zs ──o─────o─────/

Return Value

IObservable.<T>

Examples

Observable.error(new ArgumentError())
    .catchErrorDefer(ArgumentError, function(e:Error) : void
    {
        return Observable.value(1);
    })
    .subscribe(
        function(x:int) : void { trace(x); },
        function() : void { trace("Completed"); },
        function(e:Error) : void { trace("Error: " + e.message); }
    );

    // Trace output is:
    // 1
   // Completed
Clone this wiki locally