Error handling
The Observables contain a couple of operators that allow error handling, swallowing exceptions, transforming exceptions, call-finally blocks, retrying the failed sequence, and disposing resources even if an error occurs.
The catch operator
These operators enable recovering from errors by continuing the sequence:
- onErrorResumeNext: Instructs an Observable to pass control to another Observable given by a supplier, instead of invoking- onErrorwhen something goes wrong
- onErrorReturn: Instructs an Observable to emit a default supplied by a function, in case of error
- onErrorReturnItem: Instructs an Observable to emit a supplied default, in case of error
- onExceptionResumeNext: Instructs an Observable to pass control to another Observable instead of invoking- onErrorin case something goes wrong
The following example shows how to use the onErrorReturnItem method; calling it without the flatMap trick will stop the flow and output Default at the end. By deferring the call to the exception...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
                