Back
VueMediumNew

How does error handling work in Vue — what is `onErrorCaptured`?

Component-level error boundary hook

Ideal Answer

onErrorCaptured (Composition API) / errorCaptured (Options API) is a lifecycle hook that captures errors thrown by any descendant component, acting similarly to an error boundary. Returning false from the hook stops the error from propagating further up the component tree.

JavaScript
import { onErrorCaptured } from 'vue'

onErrorCaptured((err, instance, info) => {
  console.error('Captured:', err, info)
  return false // stop propagation
})

For errors outside the component render/lifecycle (e.g. in event handlers or async code), you typically need standard try/catch, and you can set a global handler with app.config.errorHandler.