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
102
Upvotes
r/cpp • u/pavel_v • Apr 02 '26
View all comments
Show parent comment
9
u/n1ghtyunso Apr 02 '26
i believe the main purpose is to wrap constructors in a try-catch in a way that lets you catch exceptions from the constructor initializer list, or from the NSDMI.
Notably, for constructors specifically, it is automatically rethrown from the catch clause.
What it does enable you is to throw a different exception.
I can't think of any use case on regular functions though. Lets you save one pair of braces i guess...