Question:
I’m wondering whether there is any good replacement for Java’s “finally” keyword (that executes regardless of whether an exception is thrown a keyword) in C++. I’m trying to switch to C++ try/catch exception handling but I’m stuck writing cleanup code in lots of places. (I’d rather not use Microsoft’s “__finally”, for portability issues.)
Answer:
Use destructors for the purpose of unconditional cleanup in C++.