[Trilinos-Users] Exceptions in destructors

Luca Bertagna luca.bertagna84 at gmail.com
Wed Aug 10 23:35:14 EDT 2016


Hello,

I recently noticed that there are quite a few compiler warnings due to
exceptions thrown inside destructors (which are (implicitly) declared
noexcept). For example, an instance that causes many warning, is the
exception thrown inside Teuchos_RCPNodeTmpl's destructor (via
TEUCHOS_TEST_FOR_EXCEPTION).

It is my understanding that throwing an exception out of a destructor is
not good practice, and should be avoided (for instance because, if the
destructor is called during the handling of another exception,
std::terminate will be called and no destructor of any other object will be
called, potentially leaking memory). Furthermore, if the base class has a
destructor `noexcept` (most likely implicitly), throwing from a derived
class is violating the base class contract of not throwing (I am not sure
whether this would result in undefined behavior though).

I was wondering if there was a particular reason why this general guideline
is not followed in trilinos.

Thanks
-- 
Luca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://trilinos.org/pipermail/trilinos-users/attachments/20160810/c1fc8e28/attachment.html>


More information about the Trilinos-Users mailing list