---
title: "<NuxtErrorBoundary>"
description: "The <NuxtErrorBoundary> component handles errors happening in its default slot."
canonical_url: "https://nuxt.com/docs/4.x/api/components/nuxt-error-boundary"
---
# \<NuxtErrorBoundary>

> The \<NuxtErrorBoundary> component handles errors happening in its default slot.

::tip
The `<NuxtErrorBoundary>` uses Vue's [`onErrorCaptured`](https://vuejs.org/api/composition-api-lifecycle#onerrorcaptured) hook under the hood.
::

When content in the default slot throws, the `#error` slot is rendered in its place. With [`experimental.ssrErrorBoundary`](https://nuxt.com/docs/4.x/guide/going-further/experimental-features#ssrerrorboundary) enabled, this also works during server-side rendering: a server-side error results in the `#error` slot being part of the HTML response (with a `200` status), and the error is passed to the client so that it hydrates into the same state. Calling `clearBoundaryError` on the client then re-renders the default slot.

In production, a server-side error that is not an HTTP error (such as one created with [`createError`](https://nuxt.com/docs/4.x/api/utils/create-error)) reaches the `#error` slot as a generic `500` error, so its message and data are not sent to the browser. HTTP errors keep their `status`, `message` and `data`.

::note
Server-side catching is controlled by the [`experimental.ssrErrorBoundary`](https://nuxt.com/docs/4.x/guide/going-further/experimental-features#ssrerrorboundary) option, which is enabled when `future.compatibilityVersion` is set to `5`. When disabled, the boundary only catches client-side errors.
::

::warning
The boundary catches everything thrown while rendering its default slot, including errors created with `fatal: true`. It does not intercept errors that bypass the component tree, such as calls to [`showError`](https://nuxt.com/docs/4.x/api/utils/show-error), errors thrown in route middleware, or `useFetch`/`useAsyncData` failures (which are returned in `error` rather than thrown). A default slot rendered by a vapor component is only caught on the client.
::

## Props

- `retryOnClient`: When the error was caught during server-side rendering, re-render the default slot on the client once mounted. Use this for content that only fails on the server (for example, a component that accesses `window`): the `#error` slot is served in the HTML, then replaced by the real content in the browser. If the default slot throws on the client as well, the `#error` slot is rendered again with the client-side error.
  - **type**: `boolean`
  - **default**: `false`
  ```vue [app/pages/example.vue]
  <template>
    <NuxtErrorBoundary retry-on-client>
      <BrokeInSSR />
      <template #error>
        <p>Loading…</p>
      </template>
    </NuxtErrorBoundary>
  </template>
  ```

## Events

- `@error`: Event emitted when the default slot of the component throws an error. For an error caught during server-side rendering, it is emitted on the server only.
  ```vue [app/app.vue]
  <template>
    <NuxtErrorBoundary @error="logSomeError">
      <!-- ... -->
    </NuxtErrorBoundary>
  </template>
  ```

## Slots

- `#error`: Specify a fallback content to display in case of error.
  ```vue [app/app.vue]
  <template>
    <NuxtErrorBoundary>
      <!-- ... -->
      <template #error="{ error, clearBoundaryError }">
        <p>An error occurred: {{ error }}</p>

        <button @click="clearBoundaryError">
          Clear error
        </button>
      </template>
    </NuxtErrorBoundary>
  </template>
  ```
  ::warning
  The slot also exposes `clearError` as a deprecated alias of `clearBoundaryError`. Use `clearBoundaryError`: if a template does not destructure `clearError` from the slot props, it calls the auto-imported [`clearError`](https://nuxt.com/docs/4.x/api/utils/clear-error) instead, which clears the **global** error.
  ::

::read-more{to="https://nuxt.com/docs/4.x/getting-started/error-handling"}
::

## Example

### Accessing `error` and `clearBoundaryError` in Script

You can access `error` and `clearBoundaryError` properties within the component's script as below:

```vue [app/app.vue]
<template>
  <NuxtErrorBoundary ref="errorBoundary">
    <!-- ... -->
  </NuxtErrorBoundary>
</template>

<script setup lang="ts">
const errorBoundary = useTemplateRef('errorBoundary')

// errorBoundary.value?.error
// errorBoundary.value?.clearBoundaryError()
</script>
```

---

- [Source](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-error-boundary.vue)


## Sitemap

See the full [sitemap](https://nuxt.com/sitemap.md) for all pages.
