title: can I use retryWhen and return an observable when a limit is reached?
body: <p>I am trying to do a retry with java Rx (version 1).</p>
  
  <p>I want to do a <code>retryWhen</code> instead of a simple <code>retry()</code> because I want when the limit is reached return an observable with certain value rather than just throw an exception.</p>
  
  <p>So, checking this <a href="https://blog.danlew.net/2016/01/25/rxjavas-repeatwhen-and-retrywhen-explained/" rel="nofollow noreferrer">https://blog.danlew.net/2016/01/25/rxjavas-repeatwhen-and-retrywhen-explained/</a> and this <a href="https://stackoverflow.com/questions/37860856/catch-error-if-retrywhens-retries-runs-out">Catch error if retryWhen:s retries runs out</a> I was able to build something that helps my purpose. </p>
  
  <pre><code>// this is only to simulate the real method that will possibly throw an exception
  public static Observable&lt;String&gt; test() {
      Observable&lt;String&gt; var = Observable.error(new IOException());
      return var;
  }
  
  
  Observable&lt;String&gt; test = test().retryWhen(attempts -&gt; {
      return attempts.zipWith(Observable.range(1, 3), (throwable, attempt) -&gt; {
          if (attempt == 3) {
              LOG.info("attempting");
              return Observable.just("completed with error");
          } else {
              return attempt;
          }
      });
  });
  
  
  
  test.doOnError(x -&gt; System.out.println("do on error message")).subscribe(s -&gt; {
      System.out.println(s);
  });
  </code></pre>
  
  <p>when I run this locally, I see the logging of attempting 3 times (as expected).</p>
  
  <p>I don't see the <code>println "do on error message"</code> (as expected)</p>
  
  <p>But I do <strong>not</strong> see the <code>completed with error</code> which I was expecting, makes me doubt I actually return the observable I want or not, what am I doing wrong?</p>
  
  <p>I also don't understand why it allows me to return an observable and an integer inside <strong>zipWith</strong>. Any ideas?</p>
  
  <p>and, is it possible to throw the exception/error from my own observable definition? something like this:</p>
  
  <pre><code>Observable&lt;String&gt; test = test().retry(3).map(value -&gt; {
  // some logic to define what to do
  Observable.error(new Exception("error");
  });
  </code></pre>