Created
May 3, 2022 12:04
-
-
Save jwerle/1bc93e303c3532abe0bdcbbea75e528d 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
function throwsWithoutAwait () { | |
return asyncError('throwsWithoutAwait') | |
} | |
async function throwsWithAwait () { | |
return await asyncError('throwsWithAwait') | |
} | |
async function asyncError (message) { | |
await sleep(250) | |
throw new Error(message) | |
} | |
async function sleep (ms) { | |
return new Promise((resolve) => setTimeout(resolve, ms)) | |
} | |
async function main () { | |
try { | |
await throwsWithoutAwait() | |
} catch (err) { | |
console.error(err.stack || err) | |
} | |
try { | |
await throwsWithAwait() | |
} catch (err) { | |
console.error(err.stack || err) | |
} | |
} | |
main() |
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
Error: throwsWithoutAwait | |
at asyncError (/home/werle/tmp/async-throw-without-await.js:11:9) | |
at async main (/home/werle/tmp/async-throw-without-await.js:20:5) | |
Error: throwsWithAwait | |
at asyncError (/home/werle/tmp/async-throw-without-await.js:11:9) | |
at async throwsWithAwait (/home/werle/tmp/async-throw-without-await.js:6:10) | |
at async main (/home/werle/tmp/async-throw-without-await.js:26:5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment