If an exception is thrown, how do you guarantee that everything allocated prior to the exception is tidied up? The answer depends to some extent on the language support. You generally have two choices: Use variable scope (for example, stack variables in C++ or Rust) Use a finally clause in a try…catch block