r/cpp • • Apr 02 '26

What happens when a destructor throws

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

48 comments sorted by

View all comments

Show parent comment

1

u/sultan_hogbo Apr 03 '26

If it doesn’t throw, what is the state of the object? Can it be considered “fully constructed and valid”?

1

u/The_JSQuareD Apr 03 '26

It's a destructor, so no. And in most cases there wouldn't even be a way to refer to the object anymore since it went out of scope.

I think you could just say the object's state is unspecified, and any code whose behavior depends on the state of the object at that point invokes UB. I believe in most cases relying on an object's state after the destructor has run would be UB anyway (so in the case with no exceptions).