In this recipe, we will discuss the issues with C++ exceptions, specifically in regard to throwing exceptions within a class destructor, something that should be avoided at all costs. The lessons learned in this recipe are important because, unlike other functions, a C++ class destructor is marked as noexcept by default, which means that if you accidentally throw an exception inside a class destructor, your program will call std::terminate(), even though the destructor my not be overtly labeled noexcept.
Learning why to never throw exceptions in destructors
Getting ready
Before beginning, please ensure that all of the technical requirements are met, including installing Ubuntu 18.04 or higher, and run the following...