No, it is not safe to call a class member function that performs cleanup operations on member variables if the constructor throws an exception. Since the constructor was not able to complete properly, the expected state of the object will not be guaranteed, and it may result in undefined behavior when calling other member functions. Instead, it is better to use a destructor to perform the cleanup operation, as it is guaranteed to be called when an object goes out of scope or is deleted.
Asked: 2023-05-24 13:27:31 +0000
Seen: 11 times
Last updated: May 24 '23