Dev Helpers
← Back

Clean up after failure

Clean up after failure. A self-contained example using the JavaScript runtime.

Open this example in the interactive library

Source code

const events = [];
try {
  await Promise.reject(new Error("failed"));
} catch {
  events.push("handled");
} finally {
  events.push("cleanup");
}
console.log(events);

Sample output

[ 'handled', 'cleanup' ]