r/cpp • u/pavel_v • Apr 02 '26
What happens when a destructor throws
https://www.sandordargo.com/blog/2026/04/01/when-a-destructor-throws
104
Upvotes
r/cpp • u/pavel_v • Apr 02 '26
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.