Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

ErrorHandler

Provides a hook for centralized exception handling.

See more...

      
      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.

Further information is available in the Usage Notes...

Methods

      
      handleError(error: any): void
    
Parameters
error any
Returns

void

Usage notes

Example

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

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