Debug Async
Await turns a rejected promise into a throw at that point. Catch around the awaited operation to observe its failure.
Where to run this
This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.
A practical example
async function load() {
try {
await Promise.reject(new Error("Sample failure"));
} catch (error) {
console.log(error.message);
}
}
await load();
What happens
The asynchronous failure is caught and reported.