onErrorCaptured()

Catches errors propagating from descendant components.

Since Vue 3.0 Spec ↗

Syntax

onErrorCaptured((err, instance, info) => boolean | void)

Parameters

NameTypeRequiredDescription
hook function No Receives the error, the source component, and an info string.

Returns

void — Return false to stop the error from propagating.

Examples

<script setup lang="ts">
import { ref, onErrorCaptured } from 'vue';

const failed = ref(false);
onErrorCaptured((err, _instance, info) => {
  console.error('Captured:', err, info);
  failed.value = true;
  return false; // stop propagation
});
</script>

<template>
  <p v-if="failed">Something went wrong.</p>
  <slot v-else />
</template>

Notes

Captures errors from child render, lifecycle hooks, watchers, and event handlers, enabling error-boundary components. Return false to prevent the error from bubbling to ancestors and the global handler. Errors thrown inside the hook itself go to the global handler.