Gurpreet Singh
Gurpreet Singh

Reputation: 58

Try catch with AngularJs

I am not sure whether try/catch is performance hit or not I want to use it in one of my AngularJs application. Will you please navigate me to right direction.

Upvotes: 0

Views: 3967

Answers (1)

harishr
harishr

Reputation: 18055

if you want to handle try/catch better or handle exception and keep the log of them write a decorate around angularjs exception handler

example here

app.config(function($provide){

    $provide.decorator("$exceptionHandler", function($delegate, $injector){
        return function(exception, cause){
            var $rootScope = $injector.get("$rootScope");
            $rootScope.addError({message:"Exception", reason:exception});
            $delegate(exception, cause);
        };
    });

});

Upvotes: 1

Related Questions