0Pricing
Vue Academy · Lesson

onErrorCaptured Lifecycle Hook

Catching errors from child components, returning false to stop propagation, error objects.

Catching Errors in Components

Vue provides the onErrorCaptured lifecycle hook to catch errors thrown by descendant components. It lets a parent intercept failures from its subtree.

The Hook Signature

onErrorCaptured receives three arguments: the error, the component instance that threw, and an info string describing where it happened.

import { onErrorCaptured } from "vue";
onErrorCaptured((err, instance, info) => {
  // handle it
});

All lessons in this course

  1. onErrorCaptured Lifecycle Hook
  2. Error Boundary Components
  3. app.config.errorHandler for Global Errors
  4. Async Error Handling in Composables
← Back to Vue Academy