title: Kotlin Flow with catch operator still completes
body: <p>I am having trouble understanding how the <code>catch</code> operator works in a kotlin <code>Flow</code>.
  <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/catch.html" rel="noreferrer">Here is the catch documentation</a></p>
  <p>Questions:</p>
  <ol>
  <li>Why doesn't the presence of a <code>catch</code> allow the <code>Flow</code> to continue upon encountering an exception, rather than complete?</li>
  <li>Placement of the <code>catch</code> operator seems to change the behavior.  Why can't I place the <code>catch</code> operator at the end of the chain to see the same result?  In my example, it only executes if I place it BEFORE <code>onEach</code>.</li>
  </ol>
  <p><a href="https://gist.github.com/gregisdumb/95709d4531fbe01983c38ace08f5a865" rel="noreferrer">Example gist</a></p>
  <p>First example, placing the <code>catch</code> BEFORE <code>onEach</code>:</p>
  <pre><code>fun main() {
      // Flow of lambdas that return a String (or throw an Exception)
      flowOf&lt;() -&gt; String&gt;({ &quot;Hello &quot; }, { error(&quot;error&quot;) }, { &quot;World&quot; })
          // Map to the result of the invocation of the lambda
          .map { it() }
          // This line will emit the error String, but then the flow completes anyway.
          // I would expect the flow to continue onto &quot;World&quot;
          .catch { emit(&quot;[Exception caught] &quot;) }
          .onEach { println(it) }
          .launchIn(GlobalScope)
  }
  </code></pre>
  <p><strong>Actual result:</strong>
  <code>Hello [Exception caught] </code></p>
  <p><strong>Expected result:</strong>
  <code>Hello [Exception caught] World</code></p>
  <p>Second example, placing the <code>catch</code> AFTER <code>onEach</code>:</p>
  <pre><code>fun main() {
      // Flow of lambdas that return a String (or throw an Exception)
      flowOf&lt;() -&gt; String&gt;({ &quot;Hello &quot; }, { error(&quot;error&quot;) }, { &quot;World&quot; })
          // Map to the result of the invocation of the lambda
          .map { it() }
          .onEach { println(it) }
          // I would expect this catch to emit, but it never gets here.
          .catch { emit(&quot;[Exception caught] &quot;) }
          .launchIn(GlobalScope)
  }
  </code></pre>
  <p><strong>Actual result:</strong>
  <code>Hello </code></p>
  <p><strong>Expected result:</strong>
  <code>Hello [Exception caught] World</code></p>
  <p>Or, since the <code>onEach</code> happens before the <code>catch</code>'s emission, the <code>catch</code>'s emission would be ignored?  In which case, the expected output would be this?:
  <code>Hello World</code></p>