Is the following code correct in terms of freeing up resources?
#include <exception>

struct A {
  ~A() { throw std::exception(); }
No, because an exception thrown from the destructor can lead to an incomplete release of resources occupied by the object (in this case, the memory, and if A was inherited from another class, there would be a resources leak, since its destructor would not be called).

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Sign Up Now
or Subscribe for future quizzes