r/cpp • • Apr 02 '26

What happens when a destructor throws

https://www.sandordargo.com/blog/2026/04/01/when-a-destructor-throws
104 Upvotes

48 comments sorted by

View all comments

Show parent comment

6

u/PJBoy_ Apr 02 '26

Ctors and dtors are special in that their function-try handlers catch exceptions thrown by construction and destruction of subobjects (member variables and bases) respectively. Because these construction/destruction operations happen outside of the ctor/dtor function bodies, and because function-try handlers in other cases only deal with exceptions thrown in the function body, it was decided that rethrowing those exceptions was a good default behaviour.

1

u/The_JSQuareD Apr 03 '26

Thanks for the explanation. But to be honest I don't really follow how the conclusion (this is sane default behavior) follows from the stated facts.