[Trilinos-Users] [EXTERNAL] Exceptions in destructors

Bartlett, Roscoe A rabartl at sandia.gov
Thu Aug 11 08:21:30 EDT 2016


This is being resolved as part of:



Dr. Roscoe A. Bartlett, PhD
Sandia National Laboratories
Trilinos Software Engineering and Integration Technologies Lead
Consortium for the Advanced Simulation of Light Water Reactors (CASL) Physics Integration Infrastructure Lead

From: Trilinos-Users [mailto:trilinos-users-bounces at trilinos.org] On Behalf Of Luca Bertagna
Sent: Wednesday, August 10, 2016 11:35 PM
To: trilinos-users at trilinos.org
Subject: [EXTERNAL] [Trilinos-Users] Exceptions in destructors


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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://trilinos.org/pipermail/trilinos-users/attachments/20160811/be4da256/attachment.html>

More information about the Trilinos-Users mailing list