JavaScript: .catch()

The .catch() method handles a rejected Promise so your code can report a useful failure instead of hiding it.

What you will learn

Minimal example

fetch("data.json")
  .then(response => response.json())
  .then(data => {
    console.log("Data loaded:", data);
  })
  .catch(error => {
    console.error("Could not load data:", error);
  });

The .catch() callback runs when the Promise is rejected or when an earlier callback in the chain throws. Put the recovery or reporting logic there instead of leaving the failure invisible.

Common mistakes