Replacement for the “Finally” Keyword

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.)

Use destructors for the purpose of unconditional cleanup in C++.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: