Customizing the angular2 exception handler

Anybody have an example of how to install a custom exception handler?

I’ve been looking into wiring this up:

The example code throws compile errors in my project.

Anyone thoughts on this?

Trying another bump…

Could we add a hook for ExceptionHandler here? Or is there an other to catch all exceptions?

You can define providers inside the @App annotation:

  providers: [provide(ExceptionHandler, {useClass:MyExceptionHandler})]

I did that and it worked, thanks.

Typescript still complains with the override documented [at the link at the top of the page]
(, even though it works. One way to make Typescript stop complaining is to use extends instead of implements - that worked without typescript type complaints. Define this before class App in app.ts:

class MyExceptionHandler extends ExceptionHandler {  
    call(error, stackTrace = null, reason = null) {
        // do something with the exception

Then add the providers line in the response above this one to your app class and this should work fine.

However: doing all the above works on catching many exceptions, still, some exceptions do not get caught using this, not sure yet why…