devxlogo

Beware of throwing exceptions from a destructor

Beware of throwing exceptions from a destructor

The most plausible way to report a failure during object construction is by throwing an exception. However, this is not recommended for destructors. The problem is that a destructor may be invoked automatically when an uncaught exception is thrown in its scope. If the called destructor invoked due to an exception also throws an exception, the result is an infinite recursion.

devx-admin

Share the Post: