title: How to continue processing after an error happens in RxJava 2?
body: <p>I have a <code>PublishSubject</code> and a <code>Subscriber</code> which I use to process a (possibly) infinite stream of preprocessed data. The problem is that some of the elements might contain some error. I'd like to ignore them and continue processing. How can I do so? I've tried something like this:</p>
  
  <pre><code>    val subject = PublishSubject.create&lt;String&gt;()
      subject.retry().subscribe({
          println("next: $it")
      }, {
          println("error")
      }, {
          println("complete")
      })
  
      subject.onNext("foo")
      subject.onNext("bar")
      subject.onError(RuntimeException())
      subject.onNext("wom")
      subject.onComplete()
  </code></pre>
  
  <p>My problem is that none of the error handling methods help me out here:</p>
  
  <blockquote>
    <p><code>onErrorResumeNext()</code> — instructs an Observable to emit a sequence of
    items if it encounters an error</p>
    
    <p><code>onErrorReturn( )</code> — instructs an
    Observable to emit a particular item when it encounters an error</p>
    
    <p><code>onExceptionResumeNext( )</code> — instructs an Observable to continue
    emitting items after it encounters an exception (but not another
    variety of throwable)</p>
    
    <p><code>retry( )</code> — if a source Observable emits an
    error, resubscribe to it in the hopes that it will complete without
    error</p>
    
    <p><code>retryWhen( )</code> — if a source Observable emits an error, pass that
    error to another Observable to determine whether to resubscribe to the
    source</p>
  </blockquote>
  
  <p>I tried <code>retry()</code> for example but it hangs my process after the error indefinitely.</p>
  
  <p>I also tried <code>onErrorResumeNext()</code> but it does not work as expected:</p>
  
  <pre><code>    val backupSubject = PublishSubject.create&lt;String&gt;()
      val subject = PublishSubject.create&lt;String&gt;()
      var currentSubject = subject
      subject.onErrorResumeNext(backupSubject).subscribe({
          println("next: $it")
      }, {
          println("error")
          currentSubject = backupSubject
      }, {
          println("complete")
      })
  
      backupSubject.subscribe({
          println("backup")
      }, {
          println("backup error")
      })
  
      currentSubject.onNext("foo")
      currentSubject.onNext("bar")
      currentSubject.onError(RuntimeException())
      currentSubject.onNext("wom")
      currentSubject.onComplete()
  </code></pre>
  
  <p>This only prints <code>foo</code> and <code>bar</code>.</p>