bhylu.com

Advertisements

Async Debugging

Give asynchronous failures context while preserving their cause. A catch near the awaited operation can report a useful stage.

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

JavaScript

async function load() {
  try {
    await Promise.reject(new Error("Offline sample"));
  } catch (cause) {
    console.log("Could not load sessions:", cause.message);
  }
}
await load();

What happens

The message identifies the failed operation and its reason.