Skip to main content
InterviewHubPRO
Section Overview
Q43

Question 43 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

86%
Vue.js & Composition API (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Vue 3 Error Handling Architecture: `onErrorCaptured` vs `app.config.errorHandler`.

senior LevelCode ExampleSystem DesignVue & Nuxt

In Simple Words:

  • onErrorCaptured: Component-level hook that intercepts errors bubbling up from descendant components. Returning false stops error propagation to the global handler, functioning like a React Error Boundary.
  • app.config.errorHandler: Global catch-all handler for reporting unhandled errors to observability systems (Sentry, Datadog).
typescript
// main.ts: Global Sentry integration
app.config.errorHandler = (err, instance, info) => {
  console.error('[Vue Global Error]', { err, info });
  Sentry.captureException(err, { extra: { lifecycleHook: info } });
};

// ErrorBoundary.vue: Reusable Component Error Boundary
import { onErrorCaptured, ref } from 'vue';

const error = ref<Error | null>(null);

onErrorCaptured((err, instance, info) => {
  error.value = err as Error;
  return false; // Stop error from bubbling to global handler
});