Error handling
We will start this section with the starter project for this chapter and dive straight into code as you already are well aware of how to set up the RxSwift
workspace and how to create one from scratch if need be. For the time being, open the starter project, and you will see that we have already created a SupportCode
file in which we have declared an enum called CustomError
, as follows:
publicenum CustomError: Error { case test }
Just to verify that we are on the same page, check the following screenshot and ensure that you have a similar project structure:

We will start with the catchErrorJustReturn
operator on the playground page.
The catchErrorJustReturn operator
The catchErrorJustReturn
operator recovers from an error event by returning an observable sequence that emits a single element and then terminates. We will create a PublishSubject
that will emit an error, as follows:
example(for: "catchErrorJustReturn") { letdisposeBag = DisposeBag() let pubSubject = PublishSubject...