Error handling

ReactiveX provides several ways to deal with errors. As explained in Chapter 1, An Introduction to Reactive Programming, errors are not special in a ReactiveX code flow. Rather, an error in ReactiveX is one possible way to end an observable. The other way is to complete it (which means that it has succeeded). There are two ways to deal with errors, depending on where the error is caught in the operators chain, as follows:

  • An observer handles errors in its on_error callback or method
  • A chain of operators can use dedicated operators to deal with errors

The first case is something that must be done in all cases. If a single observer does not handle errors then the errors go to a black hole. This is an easy way to waste hours trying to debug some code and finally see that the error was just silently dropped. If handling the errors is not obvious, then a log is the minimal implementation that allows us to debug them.

The second case allows for some interesting tricks, such as gracefully handling the errors and continuing to emit items, instead of stopping the observable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.171.51