Scope Guards
Run cleanup on scope exit.
What Is a Scope Guard?
A scope guard is an RAII object whose only job is to run a cleanup action when it goes out of scope — even on early return or exception.
The Problem It Solves
Without a guard, cleanup after an early return or a throw is easy to forget. A scope guard makes the action automatic.