What is issue in throwing an exception in a destructor?

1 answer

Answer

1246554

2026-07-29 02:25

+ Follow

If a destructor throws an exception, the instance is left in an invalid state. When an exception is thrown, the destructor automatically terminates at the point of the throw, unwinding the call stack until an exception handler is found (if one is provided). However, any resources yet to be released by the destructor, including all the instance's base classes, cannot be destroyed.

When writing your own destructors, it is important to never throw an exception. If an exception could be thrown from within your destructor, you must catch it and handle it within the same destructor -- you must not rethrow the exception.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.