- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript async Error Handling
JavaScript Asynchronous
JavaScript async Error Handling
tryandcatchhandle errors in async functions the same way as anywhere else.
A rejected promise that is awaited throws.
That means ordinary try and catch work on asynchronous code.
Example
Example
javascript
async function run() {
try {
await Promise.reject(new Error("no network"));
} catch (error) {
console.log("caught: " + error.message);
}
}
run();