Continues an observable sequence that is terminated by an exception with the next observable sequence.
Using another Observable:
second
(Observable
): A second observable sequence used to produce results when an error occurred in the first sequence.
Using a handler:
handler
(Function
): Exception handler function that returns an observable sequence given the error that occurred in the first sequence
(Observable
): An observable sequence containing the first sequence's elements, followed by the elements of the handler sequence in case an exception occurred.
/* Using a second observable */
var source = Rx.Observable.throw(new Error()).catch(Rx.Observable.just(42));
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Next: 42
// => Completed
/* Using a handler function */
var source = Rx.Observable.throw(new TimeoutError())
.catch(function (e) {
var returnValue;
if (e instanceof TimeoutError) { return Rx.Observable.just(42); }
return Rx.Observable.throw(e);
});
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Next: 42
// => Completed
File:
Dist:
Prerequisites:
- None
NPM Packages:
NuGet Packages:
Unit Tests: