I'm trying to create centralized exception handling (for all code not just Observable
s) in Angular 2, so that if there is an unhandled error it won't crash the application, but will log it. At the moment my application becomes unresponsive when there is an unhandled exception and I have to reload it. I've created an errorhandler as follows:
import { NgModule, ErrorHandler } from '@angular/core';
export class AppErrorHandler implements ErrorHandler
{
rethrowError = false;
handleError(error: any)
{
}
}
Unhandled errors do go to handleError()
, but seem to be re-thrown as my application stops working. Please help.
My question was similar to this post.
I think the answer is that there is no way to recover from an unhandled exception apart from reloading the page/application. As Günter Zöchbauer stated:
Generally exception should be handled as close as possible to the cause when there is a way to recover.
Use provide
to get your exception handler.
providers: [{provide: ErrorHandler, useClass: AppErrorHandler}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With