-
Notifications
You must be signed in to change notification settings - Fork 8
catchErrorDefer
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>
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.<T>
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