Carlos Cifuentes
AngularJS → Angular reference

$exceptionHandler in modern Angular

Overriding $exceptionHandler becomes a class that implements ErrorHandler, registered as a provider.

Before · AngularJS
app.factory('$exceptionHandler', function ($injector) {
  return function (exception, cause) {
    var tracker = $injector.get('ErrorTracker');
    tracker.report(exception, { cause: cause });
    console.error(exception);
  };
});
After · Angular
@Injectable()
export class AppErrorHandler implements ErrorHandler {
  private tracker = inject(ErrorTracker);

  handleError(error: unknown) {
    this.tracker.report(error);
    console.error(error);
  }
}

// app.config.ts
providers: [
  { provide: ErrorHandler, useClass: AppErrorHandler },
  provideBrowserGlobalErrorListeners(),
]

What changes

  • handleError receives the error only; there is no cause argument.
  • It receives errors thrown in templates, lifecycle hooks and event handlers. HTTP failures that your code catches never reach it, so handle those in an interceptor.
  • provideBrowserGlobalErrorListeners() (Angular 20 and later) also forwards window error and unhandledrejection events to the ErrorHandler.

Migration tip. In a hybrid app both handlers are active, one per framework. Send both to the same tracker and tag each report with its origin, so you can watch legacy errors go down as screens migrate.

Related

Planning a migration or a micro-frontend platform?

In a 20-minute call you describe your situation and I tell you how I'd approach it. If it isn't worth doing yet, I'll say so.

Message me on LinkedIn