Boost C++ Libraries: Ticket #3295: throwing exception / assert in destructor https://svn.boost.org/trac10/ticket/3295 <p> hello, there is, I think, a bad use of exception in the destructor of <a class="ext-link" href="http://svn.boost.org/svn/boost/trunk/boost/interprocess/sync/posix/interprocess_mutex.hpp"><span class="icon">​</span>http://svn.boost.org/svn/boost/trunk/boost/interprocess/sync/posix/interprocess_mutex.hpp</a> </p> <p> I have learned a rule at school: "no exception must be thrown within a destructor" (also see <a class="ext-link" href="https://www.securecoding.cert.org/confluence/display/cplusplus/ERR33-CPP.+Destructors+must+be+exception-safe"><span class="icon">​</span>https://www.securecoding.cert.org/confluence/display/cplusplus/ERR33-CPP.+Destructors+must+be+exception-safe</a> or <a class="ext-link" href="http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.3"><span class="icon">​</span>http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.3</a>) </p> <p> In the destructor of interprocess_mutex, an assert check for the good destruction of the posix mutex, if it fails, it throws an exception ... which is really bad in my case :) (even if I unlock the mutex just before the destructor call) </p> <p> Regards, BDM. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3295 Trac 1.4.3 Ion Gaztañaga Fri, 07 Aug 2009 09:11:49 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3295#comment:1 https://svn.boost.org/trac10/ticket/3295#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> An assertion is not an exception, and is only activated in debug mode to catch errors. It's not equivalent to throwing an exception. If the assertion fails, then you have a really severe bug in your program, showing that the object is corrupted. </p> Ticket