WithCleanup
WithCleanup[expr,cleanup] evaluates expr, running cleanup before returning the result, even if an abort, throw, etc. was generated during the evaluation of expr.
WithCleanup[init,expr,cleanup] evaluates init before evaluating expr, blocking aborts, throws, etc. in both init and cleanup.
Please visit the official Wolfram Language Reference for more details and examples on core symbols.