Concepts

Cleanup with finally

Try the free JavaScript compiler

Guarantees execution of cleanup when leaving the try block normally or abruptly. Actual runner hooks can perform similar resource disposal per test.

Formal Syntax & Structure

javascript syntaxjavascript
try { work(); } finally { dispose(); }

Working Example

Example Snippetjavascript
(async () => {const log=[];try{try{log.push("work");throw new Error("x");}finally{log.push("cleanup");}}catch{log.push("caught");}console.log(log.join(","));})()
JavaScript Reference