What this C++ constructor exception-handling question tests
This is a medium-difficulty C++ language-knowledge question that probes your understanding of how exceptions interact with object construction and memory management. Amazon and other firms use questions like this to verify that candidates understand the subtle rules governing constructor behavior and exception safety.
The question requires you to trace through code involving object initialization, exception throwing, and the order of operations during construction. You'll need to reason carefully about what gets printed (or doesn't) based on C++'s specific semantics for constructor execution and stack unwinding. A solid answer depends on knowing exactly when constructors run, when destructors run, and what happens to partially-constructed objects.
- Constructor execution order in inheritance hierarchies
- Exception propagation and stack unwinding
- Resource acquisition and cleanup during failed construction
- The RAII principle in practice