The catchError operator

Like catchErrorJustReturn, it will catch and switch to another observable. The difference is that the recovery observable does not need to immediately emit and terminate. It can continue emitting. Let's start by creating the PublishSubject, and we will also create a recovery sequence as follows:

example(for: "catchError") {    let disposeBag = DisposeBag()    let pubSubject = PublishSubject<String>()        let recoverySeq = PublishSubject<String>()}

We will use the catchError operator on the subject to print out the error and then return the recovery sequence, as shown:

let disposeBag = DisposeBag()    let pubSubject = PublishSubject<String>()        let recoverySeq = PublishSubject<String>()        pubSubject.catchError({        print("Error=", $0) ...

Get Reactive Programming with Swift 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.