👨🏫 Co-Founder of This is Learning, Organizer of AarhusJS
✍️ Writer, Speaker, FOSS Maintainer 📗 Author
🏆 Microsoft MVP 🌟 GitHub Star
🌊 Nx Champion 🦸 Angular Hero of Education
I don't see why this would be considered a caveat? Thenable promises also need to explicitly declare a Promise#catch() to handle errors? What makes it different from wrapping async/await in try-catch?
👨🏫 Co-Founder of This is Learning, Organizer of AarhusJS
✍️ Writer, Speaker, FOSS Maintainer 📗 Author
🏆 Microsoft MVP 🌟 GitHub Star
🌊 Nx Champion 🦸 Angular Hero of Education
I mean it's something to be aware of and it's often overlooked and not mentioned at all in articles discussing and guiding on async-await.
The difference between this and promises is that catch callbacks can be put specifically in any place in a promise chain. Of course, we can also do this with try-catch around a single statement, but that gets ugly pretty fast, especially if we want to keep the same variable scope between related try-catch blocks.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The most overlooked caveat of
async-await
is that we have to wrap it in atry-catch
block to handle errors by catching rejected promises.I don't see why this would be considered a caveat? Thenable promises also need to explicitly declare a
Promise#catch()
to handle errors? What makes it different from wrapping async/await in try-catch?I mean it's something to be aware of and it's often overlooked and not mentioned at all in articles discussing and guiding on
async-await
.The difference between this and promises is that catch callbacks can be put specifically in any place in a promise chain. Of course, we can also do this with
try-catch
around a single statement, but that gets ugly pretty fast, especially if we want to keep the same variable scope between relatedtry-catch
blocks.