[Trilinos-Users] Exceptions in destructors
luca.bertagna84 at gmail.com
Wed Aug 10 23:35:14 EDT 2016
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
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Trilinos-Users