3 ms·
"RAII" has some overlapping associations. Primary purpose: To guarantee the cleanup of resources during stack unwinding, after an exception is thrown, because
by xjay 4y ago
"RAII" has some overlapping associations.
Primary purpose: To guarantee the cleanup of resources during stack unwinding, after an exception is thrown, because it's tightly bound to the automatic storage duration mechanism (the static code generated to manage the stack at runtime).
Secondary purposes: 1) To immediately initialize some resource handler where it is declared. 2) To automate the cleanup of some resource when execution leaves the scope in which it was declared, also hiding explicit calls to Close, Free, Unlock, Release, etc.
To restate the source, RAII was the premise for exceptions. [1]
[1] C++ in Constrained Environments - Bjarne Stroustrup - CppCon 2022
https://www.youtube.com/watch?v=2BuJjaGuInI&t=4000s https://www.youtube.com/watch?v=2BuJjaGuInI&t=4000s