Course contentsShow
← React
Lesson 1287 of 2,39633. Error BoundariesFree lesson

What Error Boundaries Are: Catching Render Errors

Error boundaries catch JavaScript errors during rendering, in lifecycle methods, and in constructors of child components.

What Error Boundaries Are: Catching Render Errors

You'll learn what error boundaries are and how they protect your app from crashing when components fail.

The Problem with Uncaught Errors

In React, when a component throws an error during rendering, the entire application typically crashes—leaving users staring at a blank white screen. This happens because JavaScript errors during the render phase propagate up and unmount your entire component tree.

What Error Boundaries Do

Error boundaries are special React components that act like "catch blocks" for your component tree. They catch JavaScript errors that occur:

  • During rendering (when JSX is being converted to elements)
  • In lifecycle methods (like componentDidMount)
  • In constructors of child components

Think of an error boundary like a safety net under a trapeze artist. If a component "falls" (throws an error), the error boundary catches it instead of letting the entire performance (your app) come crashing down.

What They DON'T Catch

Error boundaries have limitations—they don't catch errors in:

  • Event handlers (use regular try/catch instead)
  • Asynchronous code (setTimeout, promises)
  • Server-side rendering
  • Errors thrown in the error boundary itself

Why They Matter

Without error boundaries, one broken component can take down your entire application. With them, you can isolate failures, show fallback UI (like "Something went wrong"), and keep the rest of your app functional. It's the difference between a complete outage and a graceful degradation.

Key Takeaway: Error boundaries are React's safety mechanism for catching render-time errors in child components, preventing a single broken component from crashing your entire application.