CodePark/ questions / Error handling
START PRACTICINGPRACTICE
Frontend question · React › Error handling

<Widget> is wrapped in an error boundary. Which error will the boundary catch?

An error thrown while Widget is rendering

The boundary catches the error thrown while Widget is rendering. Boundaries catch errors thrown during rendering, lifecycle methods and effects of their children.

The
onClick option is the tempting wrong answer. Event handler errors happen outside rendering, so React cannot send them to a boundary. The same is true for a setTimeout callback. A boundary's own render errors go to the next boundary above it, not to itself.