Which subobjects are destroyed when construction throws, and how does RAII make construction exception-safe?
Show answer and explanation
If a non-delegating constructor fails, the complete object's lifetime never begins and its destructor is not called. Base and member subobjects whose construction completed are destroyed in reverse completion order, as are automatic objects already created in the constructor body; the subobject whose constructor threw was never fully constructed. Storing each acquired resource in an RAII member means those completed members release themselves during unwinding. A raw resource acquired without immediately transferring it to such an owner can leak before the constructor reaches manual cleanup.
If a non-delegating constructor fails, the complete object's lifetime never begins and its destructor is not called. Base and member subobjects whose construction completed are destroyed in reverse completion order, as are automatic objects already created in the constructor body; the subobject whose constructor threw was never fully constructed. Storing each acquired resource in an RAII member means those completed members release themselves during unwinding. A raw resource acquired without immediately transferring it to such an owner can leak before the constructor reaches manual cleanup.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.