r/cpp • u/User_Deprecated • Jul 11 '26
Propagating exceptions from destructors with std::exception_ptr
https://www.sandordargo.com/blog/2026/07/08/exception_ptr
80
Upvotes
r/cpp • u/User_Deprecated • Jul 11 '26
View all comments
Show parent comment
3
u/SoerenNissen Jul 11 '26 edited Jul 12 '26
> Well, I beg to differ
https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization
> Same as raii
It lacks critical RAII features. "It can be used for cleanup" isn't RAII, dispose patterns and even C's
goto exitcan do cleanup. "It happens on scope exit" so does the stack pointer decrement, I'm sure you'll agree the stack frame isn't RAII either.In particular:
That's not guaranteed to happen. For example, if you forget to write
defer close(handle), it doesn't happen. With RAII, it's guaranteed to happen. That's why defer isn't RAII, because it doesn't do the most important part of RAII.