> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nuxt/nuxt/llms.txt
> Use this file to discover all available pages before exploring further.

# <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.
</Tip>

## Events

### `@error`

Event emitted when the default slot of the component throws an error.

```vue theme={null}
<template>
  <NuxtErrorBoundary @error="logSomeError">
    <!-- ... -->
  </NuxtErrorBoundary>
</template>
```

## Slots

### `#error`

Specify a fallback content to display in case of error.

```vue theme={null}
<template>
  <NuxtErrorBoundary>
    <!-- ... -->
    <template #error="{ error, clearError }">
      <p>An error occurred: {{ error }}</p>

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

The `#error` slot provides the following properties:

<ParamField path="error" type="unknown">
  The error object that was caught.
</ParamField>

<ParamField path="clearError" type="() => void">
  A function to clear the error and reset the component state.
</ParamField>

## Example

### Accessing `error` and `clearError` in script

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

```vue theme={null}
<template>
  <NuxtErrorBoundary ref="errorBoundary">
    <!-- ... -->
  </NuxtErrorBoundary>
</template>

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

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