Skip to content

Instantly share code, notes, and snippets.

@mmarchini
Created August 10, 2020 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmarchini/e75492000fbec60ca918edf41e90a6aa to your computer and use it in GitHub Desktop.
Save mmarchini/e75492000fbec60ca918edf41e90a6aa to your computer and use it in GitHub Desktop.
unhandled-rejections.js
async function foo() {
throw new Error();
}
foo() // 1. Unhandled at this point
.catch(() => console.error("an error occured")); // 2. Now it's handled
try {
await foo();
} catch(e) { // 3. Handled
console.error("an error occured");
}
foo(); // 4. Unhandled, but execution continues
const rejected = foo(); // 5. Unhandled on current event loop turn, but handled
// in a future turn of the event loop when the
// setTimeout callback below is executed.
setTimeout(() => rejected.catch(() => console.error("an error occured")), 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment