Ibrahim Ipek Ibrahim Ipek - 2 months ago 5x
C++ Question

How to call all destructors?

i have a big problem. When i throw an exception or call std::terminate or std::exit, the object destructor does not runs. Well this is the problem, my code is full of with this statements, because i was thinking this statements are calling destructor.

How i can solve this problem? I can not change the structure of the classes, i have 10K of code and many classes.

void Function(int Stage)
switch (Stage)
case 0:
//Somehow call the destructors
case 1:
//Give an error message and call the destructors


The destructors should run automatically upon exceptions etc.., this is exactly why they were invented in the first place.

Perhaps you created you objects using new? In which case you need to delete them explicitly (and then the destructors will run).