-
Notifications
You must be signed in to change notification settings - Fork 8
catchErrorDefer
richardszalay edited this page Sep 14, 2010
·
8 revisions
Runs a specific sequence, determined at runtime, when an error occurs
function catchErrorDefered(errorType : Class, deferFunc : Function) : IObservable.<sourceType>
Where errorType is the type of error to filter on. Errors not of this type (or a subclass) will not trigger the deferFunc.
Where deferFunc function(error : Error) : IObservable.<sourceType>
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.
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─────/
IObservable.<sourceType>
Observable.throwError(new ArgumentError())
.catchErrorDefer(function(e:Error) : void
{
return (e is ArgumentError)
? Observable.returnValue(1)
? Observable.returnValue(2);
})
.subscribe(
function(x:int) : void { trace(x); },
function() : void { trace("Completed"); },
function(e:Error) : void { trace("Error: " + e.message); }
);
// Trace output is:
// 1
// Completed