Boost C++ Libraries: Ticket #11991: Application crashes when yield/resume an coroutine after handing an exception https://svn.boost.org/trac10/ticket/11991 <pre class="wiki">#include &lt;iostream&gt; #include &lt;stdexcept&gt; #include &lt;thread&gt; #include &lt;boost/asio/io_service.hpp&gt; #include &lt;boost/asio/spawn.hpp&gt; int main() { using namespace boost::asio; using std::chrono::seconds; using yield_completion_t = detail::async_result_init&lt; yield_context, void () &gt;; io_service ios; spawn( ios, [&amp;ios]( auto yield ) { try { throw std::runtime_error{ "" }; } catch( ... ) { std::cerr &lt;&lt; "[1] " &lt;&lt; std::endl; yield_completion_t completion{ yield_context{ yield } }; auto handler = completion.handler; ios.post( [=] { std::this_thread::sleep_for( seconds{ 1 } ); asio_handler_invoke( handler, &amp;handler ); } ); completion.result.get(); std::cerr &lt;&lt; "[2] " &lt;&lt; std::endl; } } ); // needs more than one thread std::thread t{ [&amp;]{ ios.run(); } }; ios.run(); t.join(); return 0; } </pre><p> Prints: </p> <pre class="wiki">[1] [2] </pre><p> and crashes. </p> <p> Debugger points to <code>_FindAndUnlinkFrame</code> (inside <code>trnsctrl.cpp</code> file): <code>pCurFrameInfo-&gt;pNext</code> causes AV because pCurFrameInfo is null. </p> <p> VS 2015, Win7 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11991 Trac 1.4.3 olli Wed, 17 Feb 2016 08:34:30 GMT owner, component changed https://svn.boost.org/trac10/ticket/11991#comment:1 https://svn.boost.org/trac10/ticket/11991#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">olli</span> to <span class="trac-author">chris_kohlhoff</span> </li> <li><strong>component</strong> <span class="trac-field-old">coroutine</span> → <span class="trac-field-new">asio</span> </li> </ul> <p> You must not install/call an async_result inside a exception handler (catch-block). The exception handler might reside on the stack or might removed from the stack (including the variables) if left. Especially MS is unspecific what happens under the hood (in contrast to C++-Itanium exception ABI). </p> <p> A small modification of your code prevents the error (async_result is allocated outside the exception handler): </p> <pre class="wiki">spawn( ios, [&amp;ios]( auto yield ){ bool failed = false; try{ throw std::runtime_error{ "" }; }catch( ... ){ std::cerr &lt;&lt; "[1] " &lt;&lt; std::endl; failed = true; } if (failed){ yield_completion_t completion{ yield_context{ yield } }; auto handler = completion.handler; ios.post( [=] { std::this_thread::sleep_for( seconds{ 1 } ); asio_handler_invoke( handler, &amp;handler ); } ); completion.result.get(); std::cerr &lt;&lt; "[2] " &lt;&lt; std::endl; } } ); </pre> Ticket