Rx framework — IObservable<T>.Catch and IObservable<T>.OnErrorResumeNext

Like IObservable<T>.Concat, the IObservable<T>.Catch exten­sion method con­cate­nates an observ­able col­lec­tion with anoth­er.

How­ev­er, unlike the Con­cat method where the sub­scrip­tion to the sec­ond observ­able col­lec­tion hap­pens after the first had com­plet­ed, in the Catch method the sub­scrip­tion to the sec­ond col­lec­tion hap­pens after and only after the first had except­ed!

Which begs a very good ques­tion:

What if I want to con­cate­nate an observ­able col­lec­tion with anoth­er regard­less of whether the first suc­ceeds or not?

Well, the answer to that ques­tion is IObservable<T>.OnErrorResumeNext, which always sub­scribes to the sec­ond observ­able col­lec­tion at the end of the first.


Like so many oth­er merge-type exten­sion meth­ods in Rx, there are two flavours to choose from when using the Catch or OnError­Re­sumeNext meth­ods. Either as exten­sion method:

var zs = xs.Catch(ys);

var zs2 = xs.OnErrorResumeNext(ys);

or as sta­t­ic meth­ods which give you the option to merge more than two observ­able col­lec­tions:

var zs = Observable.Catch(xs, ys, us, vs);

var zs2 = Observable.OnErrorResumeNext(xs, ys, us, vs);

Liked this post? Why not support me on Patreon and help me get rid of the ads!