I have a question regarding exceptions in contructors.
Picture that I have the following class:
Now I have a simple derived class as follows:
What happens if an exception is thrown within the constructor of the DerivedObject, like so:
class DerivedObject : public BaseObject
I am familiar with catching exceptions within constructors to prevent memory loss. However, in this specific case, will the destructor of the BaseObject be called automatically after the exception is thrown?
// Contructor - do something
// EXCEPTION THROWN HERE
// Free newly created heap objects
My guess is that it won't, but I'm not sure. Should I ensure that I free any memory held by BaseObject in the catch block of DerivedObject constructor?
Edit : Oops there was an exception in the title of this thread.