[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/core/ErrorHandler [Back]  [Original]

ErrorHandler Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/core

ErrorHandler

Class
stable

Provides a hook for centralized exception handling.

Unhandled errors in Angular

On this page

    arrow_upward_alt Back to the top

    API

        
          class ErrorHandler {  handleError(error: any): void;  optional onViewError(error: Error, details: ErrorDetails): void;}
        
        

    handleError

    void
    @paramerrorany
    @returnsvoid

    onViewError

    void

    Callback to handle errors happening during the rendering of a component/directive view.

    @paramerrorError

    The error that was thrown.

    @paramdetailsErrorDetails

    Additional information about the error.

    @returnsvoid

    Description

    Provides a hook for centralized exception handling.

    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.

    Usage Notes

    Example

    class MyErrorHandler implements ErrorHandler {
      handleError(error) {
        // do something with the exception
      }
    }
    
    // Provide in standalone apps
    bootstrapApplication(AppComponent, {
      providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
    })
    
    // Provide in module-based apps
    @NgModule({
      providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
    })
    class MyModule {}
    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page