try { array<MyClass *> uhi = createMyClasses(); for (int i = 0, n = uhi.size(); i < n; i++) { uhi[i].uhirinko(); } } catch (...) for (int i = 0, n = uhi.size(); i < n; i++) { delete uhi[i]; } throw; } for (int i = 0, n = uhi.size(); i < n; i++) { delete uhi[i]; }