Example 1 — finally Cleanup
finally runs whether or not an error occurred.
let status = "start";
try {
throw new Error("fail");
} catch (err) {
status = "caught";
} finally {
status += "+done";
}
console.log(status); How It Works
- throw jumps. Execution enters
catch. - finally always. Cleanup runs after catch.
