The catch() operator

The catch() operator lets you try another observable. When an error occurs it can be used at the class or instance level.

At the class level, the catch() operator has the following signature:


As you can see, it receives an arbitrary number of arguments:

  • observables: It is an arbitrary number of observables to be used as fallback in the first failure. They are attempted from left to right until an Observable succeeds.

The simplest way to see this operator in action is with the following example:

Rx.Observable.catch(     Rx.Observable.throw(new Error('An error occurred')),     Rx.Observable.just('Hello') ).subscribe(   (m)=> console.log(m),   (e)=> console.log('Error found') ); 

In this example, ...

Get Mastering Reactive JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.