-
Notifications
You must be signed in to change notification settings - Fork 22.8k
Open
Labels
Content:Learn:ExpressLearning area Express docsLearning area Express docs
Description
MDN URL
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:
async function myFunction {
// ...
await someObject.methodThatReturnsPromise();
// ...
await aFunctionThatReturnsPromise();
// ...
}
try {
// ...
myFunction();
// ...
} catch (e) {
// error handling code
}
What did you expect to see?
Something like this with a proper explanation:
async function myFunction {
// ...
try {
await someObject.methodThatReturnsPromise();
} catch(e) {
// error handling code
}
// ...
try {
await aFunctionThatReturnsPromise();
} catch(e) {
// error handling code
}
// ...
}
myFunction();
or
async function myFunction {
// ...
await someObject.methodThatReturnsPromise();
// ...
await aFunctionThatReturnsPromise();
// ...
}
myFunction().catch((e) => {
// error handle error
});
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
Metadata
Metadata
Assignees
Labels
Content:Learn:ExpressLearning area Express docsLearning area Express docs