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

> The \<NuxtErrorBoundary> component handles client-side 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.
::

## Events

- `@error`: Event emitted when the default slot of the component throws an error.
  ```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, clearError }">
        <p>An error occurred: {{ error }}</p>

        <button @click="clearError">
          Clear error
        </button>
      </template>
    </NuxtErrorBoundary>
  </template>
  ```

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

## Example

### Accessing `error` and `clearError` in Script

You can access `error` and `clearError` 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?.clearError()
</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.
