Boost C++ Libraries: Ticket #9796: std::system_error cannot be catched after is rethrown with boost::rethrow_exception() https://svn.boost.org/trac10/ticket/9796 <p> boost::rethrow_exception() loses information about the system_error exception type. See the following example code, which when compiled with g++ --std=c++11, displays <em>exception caught</em> instead of <em>system error caught</em>: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;system_error&gt; #include &lt;boost/exception/all.hpp&gt; void do_something() { try { // let's assume the following exception is thrown inside some // system library function... throw std::system_error(EDOM, std::system_category()); } catch (...) { boost::rethrow_exception(boost::current_exception()); } } int main() { try { do_something(); } catch (const std::system_error &amp; ex) { std::cout &lt;&lt; "system error caught\n"; } catch (const std::exception &amp; ex) { std::cerr &lt;&lt; "exception caught\n"; } return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9796 Trac 1.4.3 Emil Dotchevski Thu, 20 Mar 2014 18:28:56 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9796#comment:1 https://svn.boost.org/trac10/ticket/9796#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> I understand that in this case the throw site might not be in your code, but see <a href="http://www.boost.org/doc/libs/release/libs/exception/doc/enable_current_exception.html">http://www.boost.org/doc/libs/release/libs/exception/doc/enable_current_exception.html</a>. If possible, use boost::throw_exception instead of throw. </p> Ticket anonymous Fri, 21 Mar 2014 07:35:41 GMT <link>https://svn.boost.org/trac10/ticket/9796#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9796#comment:2</guid> <description> <p> As I wrote this throw is from a std::library function (like for example std::thread().detach();, see [trac does not allow me to add links, so find it on google by yourself]), so throw_exception cannot be used. </p> <p> Besides if you replace std::system_error with for example std::logic_error, the code works - the logic_error is properly catched. This means that <strong>this bug is not invalid</strong>. Please reopen it, and fix it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 21 Mar 2014 07:36:11 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/9796#comment:3 https://svn.boost.org/trac10/ticket/9796#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> Ticket Emil Dotchevski Fri, 21 Mar 2014 20:51:35 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9796#comment:4 https://svn.boost.org/trac10/ticket/9796#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> From <a href="http://www.boost.org/doc/libs/release/libs/exception/doc/current_exception.html">http://www.boost.org/doc/libs/release/libs/exception/doc/current_exception.html</a>: "Whenever current_exception fails to properly copy the current exception object, it returns an exception_ptr to an object of type that is as close as possible to the original exception type, using unknown_exception as a final fallback." This is to say that your code must be prepared to deal with boost::current_exception failing to give you an object of the exact type. </p> <p> (The std::logic_error exception is also not properly cloned which can lead to slicing. Similar support for std::system_error is more problematic because it isn't available in all implementations yet. Where it is available, in all likelihood std::current_exception is available as well, so just use that.) </p> Ticket