This is the archived documentation for Angular v5. Please visit angular.io to see documentation for the current version of Angular.

ErrorHandler

npm Package @angular/core
Module import { ErrorHandler } from '@angular/core';
Source core/src/error_handler.ts

Provides a hook for centralized exception handling.

Overview

      
      class ErrorHandler {
  handleError(error: any): void
}
    

Description

The default implementation of ErrorHandler prints error messages to the console. To intercept error handling, write a custom exception handler that replaces this default as appropriate for your app.

Example

      
      class MyErrorHandler implements ErrorHandler {
  handleError(error) {
    // do something with the exception
  }
}

@NgModule({
  providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
})
class MyModule {}
    

Members

      
      handleError(error: any): void