Boost C++ Libraries: Ticket #10462: throw exception inherits two std::exception https://svn.boost.org/trac10/ticket/10462 <pre class="wiki">// example class my_exception: public std::exception { }; try { boost::throw_exception(my_exception()); } catch( my_exception &amp; e) {... } </pre><p> Inheritance of e </p> <pre class="wiki"> -&gt; ... clone_impl&lt;boost::exception_detail::error_info_injector&lt;my_exception&gt; &gt; -&gt; -&gt; my_exception -&gt; -&gt; -&gt; std::exception ... -&gt; std::exception </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10462 Trac 1.4.3 Emil Dotchevski Fri, 05 Sep 2014 03:03:19 GMT <link>https://svn.boost.org/trac10/ticket/10462#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10462#comment:1</guid> <description> <p> Is it possible that my_exception derives from std::exception privately? </p> <p> There are checks which should fail with ambiguous implicit conversion errors in case std::exception is derived from multiple times. I'm noticing, however, that the relevant unit test throw_exception_test.cpp doesn't explicitly verify this. </p> <p> Could you help me diagnose the error? Insert the following snipped into throw_exception_test.cpp, run it, and let me know if it fails for you. It works on my darwin build (the idea of this insertion is that if std::exception is derived from multiple times, the catch(std::exception&amp;) would fail since the conversion would be ambiguous.) </p> <pre class="wiki">@@ -76,7 +76,21 @@ throw_fwd( void (*thrower)(int) ) { try { - thrower(42); + try + { + thrower(42); + } + catch( + std::exception &amp; ) + { + throw; + } + catch( + ... ) + { + BOOST_ERROR("throw_fwd failed to catch std::exception, possibly because it was derived from multiply."); + throw; + } } catch( boost::exception &amp; x ) </pre><p> Thanks, Emil </p> </description> <category>Ticket</category> </item> <item> <author>gregory.boero-teyssier@…</author> <pubDate>Tue, 09 Sep 2014 09:45:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10462#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10462#comment:2</guid> <description> <p> hello the file you're named throw_exception_test.cpp doesn't compile with or without your modification </p> <p> list of error : </p> <pre class="wiki">Erreur 4 error LNK1120: 3 externes non rΘsolus Visual Studio 2013\Projects\ggcTestBoost\x64\Debug\ggcTestBoost.exe ggcTestBoost Erreur 2 error LNK2019: symbole externe non rΘsolu "void __cdecl boost::exception_test::throw_test_exception&lt;struct boost::exception_test::derives_boost_exception_virtually&gt;(int)" (??$throw_test_exception@Uderives_boost_exception_virtually@exception_test@boost@@@exception_test@boost@@YAXH@Z) rΘfΘrencΘ dans la fonction "void __cdecl tester&lt;struct boost::exception_test::derives_boost_exception_virtually&gt;(void)" (??$tester@Uderives_boost_exception_virtually@exception_test@boost@@@@YAXXZ) C:\Users\a588420\Documents\Visual Studio 2013\Projects\ggcTestBoost\ggcTestBoost\throw_exception_test.obj ggcTestBoost Erreur 1 error LNK2019: symbole externe non rΘsolu "void __cdecl boost::exception_test::throw_test_exception&lt;struct boost::exception_test::derives_boost_exception&gt;(int)" (??$throw_test_exception@Uderives_boost_exception@exception_test@boost@@@exception_test@boost@@YAXH@Z) rΘfΘrencΘ dans la fonction "void __cdecl tester&lt;struct boost::exception_test::derives_boost_exception&gt;(void)" (??$tester@Uderives_boost_exception@exception_test@boost@@@@YAXXZ) C:\Users\a588420\Documents\Visual Studio 2013\Projects\ggcTestBoost\ggcTestBoost\throw_exception_test.obj ggcTestBoost Erreur 3 error LNK2019: symbole externe non rΘsolu "void __cdecl boost::exception_test::throw_test_exception&lt;struct boost::exception_test::derives_std_exception&gt;(int)" (??$throw_test_exception@Uderives_std_exception@exception_test@boost@@@exception_test@boost@@YAXH@Z) rΘfΘrencΘ dans la fonction "void __cdecl tester&lt;struct boost::exception_test::derives_std_exception&gt;(void)" (??$tester@Uderives_std_exception@exception_test@boost@@@@YAXXZ) C:\Users\a588420\Documents\Visual Studio 2013\Projects\ggcTestBoost\ggcTestBoost\throw_exception_test.obj ggcTestBoost </pre><p> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Tue, 09 Sep 2014 19:57:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10462#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10462#comment:3</guid> <description> <p> You mean it doesn't link. You need to link helper2.cpp or run boost build, the Jamfile in that directory works. </p> </description> <category>Ticket</category> </item> <item> <author>gregory.boero-teyssier@…</author> <pubDate>Wed, 10 Sep 2014 06:41:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10462#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10462#comment:4</guid> <description> <p> yes sure it won't work like this, i haven't seen the </p> <pre class="wiki">#include "helper2.hpp" </pre><p> in the file. Sorry i'm new in c++ world but even now it's not working </p> <pre class="wiki">Erreur 1 error C2039: 'throw_function_' : n'est pas membre de 'exception1' Erreur 2 error C2039: 'throw_file_' : n'est pas membre de 'exception1' Erreur 3 error C2039: 'throw_line_' : n'est pas membre de 'exception1' </pre><p> Let me know if i forgot to do something. </p> <p> Thanks, grégory </p> </description> <category>Ticket</category> </item> </channel> </rss>