Created
August 10, 2020 21:54
-
-
Save mmarchini/e75492000fbec60ca918edf41e90a6aa to your computer and use it in GitHub Desktop.
unhandled-rejections.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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