The C++ language guarantees that destructors run at specific times even if an exception is thrown. You can use this to make sure that other cleanup work gets done. That is what smart pointers do.
See All 304 Episodes of "Take Up Code"