Last active
January 18, 2023 08:06
-
-
Save hsenag/03d6d0a8e99e3894936512bba162b527 to your computer and use it in GitHub Desktop.
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
// This code aborts (paste into a shell command-line, or drop the first and last lines and put in a `.js` or `.ts` file): | |
node << END | |
console.log("start"); | |
async function throws() { | |
throw new Error("oops"); | |
} | |
async function main() { | |
try { | |
const throwsPromise = throws(); | |
await new Promise(setImmediate); | |
await throwsPromise; | |
} catch (e) { | |
console.log("caught"); | |
} | |
console.log("finished"); | |
} | |
main(); | |
END | |
// But this doesn't: | |
node << END | |
console.log("start"); | |
async function throws() { | |
throw new Error("oops"); | |
} | |
async function main() { | |
try { | |
const throwsPromise = throws(); | |
await throwsPromise; | |
} catch (e) { | |
console.log("caught"); | |
} | |
console.log("finished"); | |
} | |
main(); | |
END | |
// And neither does this: | |
node --unhandled-rejections=none << END | |
console.log("start"); | |
async function throws() { | |
throw new Error("oops"); | |
} | |
async function main() { | |
try { | |
const throwsPromise = throws(); | |
await new Promise(setImmediate); | |
await throwsPromise; | |
} catch (e) { | |
console.log("caught"); | |
} | |
console.log("finished"); | |
} | |
main(); | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment