New operator for arrays takes care of this. If some of the array element constructors throws, the memory allocated for the array is deleted. Then, the exception is passed up to the caller of new.
If the Stack constructor is called by the new e.g.:
|
Stack::Stack* s = new Stack::Stack();
| |
This new will catch the exception, and deallocate the memory for stack, so no memory leak will occur, and rethrow. If the Stack object was allocated on the stack, normal rules for handling exceptions apply (the stack is unwound, destructors are called - no memory leak).
Nevertheless, according to Google style guide, constructors should not allocate memory / resources, because in more complex programs it is difficult to proove exception-safety. On the other side, constructors creating objects in illegal state, and requiring a special call to "init", contradict basic rule of OOP - that objects should be created always in valid state.
BTW: On some platforms new does not raise exceptions. E.g. on Linux you won't get it. New will pass, even if there is not enough physical memory - your app will get killed when you try to initialize this memory (probably somewhere in the constructor - but this will not be a catchable exception).