title: What is the currently handled exception after co_await?
body: <p>GCC permits one to resume C++20 coroutines from <code>catch</code> sections and in the coroutine to call <code>co_await</code> again from its <code>catch</code> sections.</p>
  <p>What is considered then the current handled exception in such cases?</p>
  <p>Please consider an example:</p>
  <pre><code>#include &lt;coroutine&gt;
  #include &lt;iostream&gt;
  
  struct ReturnObject {
    struct promise_type {
      ReturnObject get_return_object() { return { std::coroutine_handle&lt;promise_type&gt;::from_promise(*this) }; }
      std::suspend_always initial_suspend() { return {}; }
      std::suspend_always final_suspend() noexcept { return {}; }
      void unhandled_exception() {}
      void return_void() {}
    };
    std::coroutine_handle&lt;promise_type&gt; h_;
  };
  
  ReturnObject coroutine()
  {
    try {
        std::cout &lt;&lt; &quot;Exception 1 being thrown\n&quot;;
        throw 1;
    }
    catch( int a ) {
        std::cout &lt;&lt; &quot;Exception caught in coroutine &quot; &lt;&lt; a &lt;&lt; std::endl; 
        co_await std::suspend_always{};
        try {
          std::cout &lt;&lt; &quot;Current exception being rethrown\n&quot;;
          throw;
        }
        catch( int b ) {
          std::cout &lt;&lt; &quot;Exception caught in coroutine &quot; &lt;&lt; b &lt;&lt; std::endl; 
        }
    }
  }
  
  int main()
  {
    auto h = coroutine().h_;
  
    try {
        std::cout &lt;&lt; &quot;Exception 0 being thrown&quot; &lt;&lt; std::endl;
        throw 0;
    }
    catch( int a ) { 
        std::cout &lt;&lt; &quot;Exception &quot; &lt;&lt; a &lt;&lt; &quot; caught in main&quot; &lt;&lt; std::endl; 
        h();
    }
  
    h();
    h.destroy();
  }
  </code></pre>
  <p>It prints ( <a href="https://gcc.godbolt.org/z/4deoG7Pnh" rel="nofollow noreferrer">https://gcc.godbolt.org/z/4deoG7Pnh</a> ):</p>
  <pre><code>Exception 0 being thrown
  Exception 0 caught in main
  Exception 1 being thrown
  Exception caught in coroutine 1
  Current exception being rethrown
  Exception caught in coroutine 0
  </code></pre>
  <p>Here I am mostly interesting in the last line, since it shows that <code>throw;</code> re-throws <code>0</code> and not <code>1</code>, which was actually the one being processed. Is it correct?</p>