An error arises when a program’s execution has unexpected results. There are 3 usual errors in Angular:
Error handling in Angular is done with the help of the handleError
function. This function allows centralized exception handling and is provided to the application when the application is initialized.
The handleError
function, by default, only prints error messages to the console. However, a customized exception handler can be added to intercept and modify the default behavior.
class MyErrorHandler implements ErrorHandler {//this function is called when the application throws an errorhandleError(error: Error) {// handle the exception here}}@NgModule({providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]})class MyModule {}
Free Resources