Course contentsShow
← JavaScript
Lesson 1280 of 2,72329. PromisesFree lesson

Where .catch() Catches Errors

Understand that .catch() handles rejections from any preceding Promise or thrown error in the chain.

Where .catch() Catches Errors

You'll learn: How .catch() acts as a safety net for any rejection or error that occurs anywhere before it in the Promise chain.

The Safety Net Placement

When you attach .catch() to a Promise chain, it doesn't just handle errors from the immediately preceding Promise—it catches any rejection or thrown error from any Promise or .then() callback that comes before it in the chain.

Think of .catch() like a drain at the bottom of a sloped surface. No matter where water (an error) spills on that surface, it all flows down to the drain.

How Errors Propagate

If a Promise rejects or a .then() callback throws an error, that error skips all subsequent .then() calls and jumps directly to the next .catch() in the chain:

fetch('/api/data')
  .then(response => response.json())  // Error here? Skips next .then()
  .then(data => data.value.toUpperCase())  // Skipped if previous rejected
  .catch(error => {
    // Catches errors from fetch(), first .then(), OR second .then()
    console.error('Something failed:', error);
  });

If the fetch() fails, .catch() handles it. If response.json() fails, .catch() handles it. If data.value is undefined and throws an error, .catch() handles that too.

One Catch for All

You don't need a separate .catch() after every .then(). A single .catch() at the end guards the entire chain above it. This makes error handling much cleaner than nested callbacks where you'd need error checks at every level.

Key Takeaway: .catch() catches rejections and thrown errors from any preceding step in the Promise chain, not just the immediately previous one.