Exceptions enable you to detect and handle anomalous runtime conditions promptly. However, they also complicate the design of your program as they increase the number of possible execution paths. In most cases, implementing the "
resource acquisition is initialization" idiom guarantees that data isn't destroyed and that resources are always released. However, this idiom isn't always an ideal solution. The following sections present a more refined technique for ensuring proper cleanup in an exception-enabled environment.

How do you ensure that critical cleanup code always executes regardless of whether an exception has occurred?

Use a local class's destructor to ensure the unconditional execution of cleanup code.