> For the complete documentation index, see [llms.txt](https://bharat-tiwari.gitbook.io/our-tech-journal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bharat-tiwari.gitbook.io/our-tech-journal/react/error-handling.md).

# Error Handling

## Error boundaries (in React 16+)

Use `componentDidCatch` in the Error Boundary component and wrap your error prone child components or the whole App inside this Error Boundary component.

Error boundaries cannot catch errors that could happen in some async call or in some event handler

## Use try-catch and window\.onerror

handle errors in catch blocks, throw meaningful errors and propogate errors up till window

## have a Global Logger provider to Log errors to your cloud watch or somewhere in server

call this global logger in `window.onerror`

## Use Sentry or Catch.js to log the errors that happen on client side to the server
