-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect explanation of catching errors with asynchronous JavaScript in Express Tutorial #37719
Comments
Have you tried it? My understanding is that as long as the potentially throwing function(s) are awaited, which they are, then this construction should work. So would your first example. Not sure about the second. @Josh-Cena Can you advise whether the current code is OK? I'm pretty sure I tested this, but perhaps not. |
Indeed, this would never catch anything from |
Thanks both. I had figured that since Anyhow, I guess we should fix https://github.com/mdn/express-locallibrary-tutorial first and then update the docs. @granteckels Did you want to do the updates? |
The actual repo doesn't contain this code. It's just used as an example when explaining async JavaScript in the docs. So only the docs need to be updated. And, yes, I can do this. |
Thank you very much! |
MDN URL
https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/Express_Nodejs/mongoose
What specific section or headline is this issue about?
Database APIs are asynchronous
What information was incorrect, unhelpful, or incomplete?
In this section, in the part where it explains how to catch errors from async functions, I believe it's wrong. It puts the try...catch block on the async function call instead of inside the function or by running catch() on the async function call. In the current code, the error will not be caught.
This is the code in question:
What did you expect to see?
Something like this with a proper explanation:
or
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
No response
MDN metadata
No response
The text was updated successfully, but these errors were encountered: