O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

Rx.Observable.catch(observables); 

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required