Skip to main content

Error Handling and Error Boundaries

Learn Error Handling and Error Boundaries (Phase 15 · Advanced Rendering Concepts (Advanced), ReactJS) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Where errors can happen in React • Render errors (exceptions while rendering) unmount the whole tree and show a blank page unless caught by an error boundary . • Event handler and async errors are not caught by boundaries: use try/catch (and .catch on promises) and show an error state. • An error boundary is a class component with static getDerivedStateFromError (switch to fallback UI) and componentDidCatch (log). The react-error-boundary package provides a ready-made component and hooks.

More lessons in Phase 15 · Advanced Rendering Concepts (Advanced)