title: RxJava Zip Operator Error Handling with Iterator
body: <p><strong>Background</strong></p>
  
  <p>I have a process that uses RxJava to get data from different locations based on a list. Each item is got through a different method (all returning Observables.). Due to having N items to get the logic operator to use is <code>zip</code> with an iterator.</p>
  
  <p><strong>The Problem</strong></p>
  
  <p>The code below works as expected but it seems "wrong" that I need a <code>try-catch</code> block to catch the Exception that is thrown by <code>getBigFoo()</code> - that returns a <code>FooNotFoundException</code>. Do not the other error related operators cover this, such as <code>onErrorResumeNext()</code> and <code>onErrorReturn()</code>?</p>
  
  <pre><code>private Observable&lt;Bar&gt; processFoos(List&lt;Foo&gt; foos) {
  
          List&lt;Observable&lt;? extends IBar&gt;&gt; observablesToZip = new ArrayList&lt;&gt;();
  
          for(Foo foo : foos) {
  
              switch (foo.getType()) {
  
                  case BIG_FOO :
  
                      try {
                          observablesToZip.add(getBigFoo(foo.getId()));
                      } catch (Exception exception) {
                          //do nothing - but this seems wrong
                      }
              }
          }
  
          return Observable.zip(observablesToZip, results -&gt; mergeFoosIntoBar(results));
      }
  </code></pre>
  
  <p><strong>Attempts Made</strong></p>
  
  <p>The attempt below doesn't seem to catch the Exception generated. I don't understand why as there are technically no upstream or downstream items in the sequence, so <code>Observable.empty()</code> should work?</p>
  
  <pre><code>private Observable&lt;Bar&gt; processFoos(List&lt;Foo&gt; foos) {
  
          List&lt;Observable&lt;? extends IBar&gt;&gt; observablesToZip = new ArrayList&lt;&gt;();
  
          for(Foo foo : foos) {
  
              switch (foo.getType()) {
  
                  case BIG_FOO :
                     observablesToZip.add(getBigFoo(foo.getId().onErrorResumeNext(Observable.empty()));
              }
          }
  
          return Observable.zip(observablesToZip, results -&gt; mergeFoosIntoBar(results));
      }
  </code></pre>