After the getA() call, the first exception is thrown, the so-called unwinding of the stack is triggered, and the object is destroyed. While the object is destroyed, its destructor throws another exception that leaves the body of the destructor and (since this happens during the unwinding of the stack), this causes terminate() be immediately called by the C ++ runtime and the program terminates .
In the second fragment that you sent, the exception is thrown in the constructor, so the constructor does not end, and the destructor is never called (since destructors are called only for fully constructed objects), so there is no way for terminate() call.
source share