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

2

u/kpt_ageus Apr 02 '26

You use try catch to prevent termination. And your program terminates anyway.

I apologize for sounding high and mighty, rude even, but unless you don't know what std::terminate does I can't imagine how it's not immediately obvious why this is bad.

0

u/fluorihammastahna Apr 02 '26

It's not that your comment is rude, it's simply that it's RTFM-level of uninformative. Any seasoned C++ developer should be alert about these articles, like "Oh crap what basic misunderstanding do I have now about this basic feature". I definitely expect caveats about terminate I am not aware of. I use terminate for things like logical errors that cannot be enforced via language, like reaching a default: where I've dealt with all enum values.

Terminating or just letting the program die is much better than handling an exception to let the program continue in the vast majority of cases. In the first case, you will always be sure that there is something to fix, and in the second at the very least you are semantically mixing up runtime events with actual errors, and at worst letting critical problems slip.