🔰error handling

JSasynchronousawait ⟩ error handling

catch await errors by try...catch.

(async () => {
  // catch await errors by try...catch statement.
  try {
    let response = await fetch(url);
  } catch(err) {
    console.log(err);
  }
})();
(async () => {
    let response = await fetch(url);
})().catch(err => {    // catch a rejected Promise returned by async func
    console.log(err)
});

Last updated