In a real-world scenario, no system is perfect. As we discussed in the previous section, resilience is one of the qualities of a reactive system. How a system handles errors and exceptions decides the future of that system. Early detection and the seamless handling of errors makes a system consistent and responsive. Compared to imperative programming approaches, the reactive programming model helps the user to handle errors separately, as and when the system detects an error or throws an exception.
In this section, we will take a look at how to handle exceptions and errors by using the RxCpp
library. There are a variety of RxCpp
Operators that can be used to react to on_error
notifications from Observables. For instance, we might:
- Handle the error by exiting from the sequence gracefully
- Ignore the error and switch over to a backup Observable to continue the sequence
- Ignore the error and emit a default value
- Ignore the error and immediately try to restart...