4 ms·
To be precise, with proper exception handling, the former will throw, but the destructor will also be called as part of the stack-unwind.
by delta_p_delta_x 3y ago
To be precise, with proper exception handling, the former will throw, but the destructor will also be called as part of the stack-unwind.
- imron 3y agoI'm not sure I understand. The former 'int main(){S s;}' is just calling the default constructor which doesn't throw. Only the latter 'int main(){S s(42);}' throws, and it will never call the destructor. Or maybe I've misunderstood? Perhaps modify the code example I linked to on godbolt to show what you mean?
- delta_p_delta_x 3y agoMy bad, I swapped 'former' and 'latter'. What I simply meant is this: https://godbolt.org/z/Y7W6GenbE https://godbolt.org/z/Y7W6GenbE If an exception is properly handled (i.e. inside a try-catch block), the destructor of any object that might be destroyed after leaving said scope, is called as part of the stack-unwind, guaranteed by the specification.