I have a factory written to override the built in $exceptionHandler because I plan on creating a backend service that I can log to from the frontend. For now though, I just want to catch the exception, log it to the console, and then throw it, knowing that the console.log will be replaced with a service call.
angular.module('exceptionOverride', []).factory('$exceptionHandler', function() {
return function(exception) {
console.log(exception);
throw exception;
};
});
In the init function of my controller, I put
var x = n + 1 so it would throw an error due to n being undefined.
However, on controller init, this happens:
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:6 Uncaught ReferenceError: n is not definedinit @ taxAccountNameController.js:17taxAccountNameController @ taxAccountNameController.js:12invoke @ angular.js:4478instantiate @ angular.js:4486(anonymous function) @ angular.js:9151$interpolate.compile @ angular-ui-router.js:4018invokeLinkFn @ angular.js:8789nodeLinkFn @ angular.js:8289compositeLinkFn @ angular.js:7680publicLinkFn @ angular.js:7555updateView @ angular-ui-router.js:3959directive.compile @ angular-ui-router.js:3927invokeLinkFn @ angular.js:8789nodeLinkFn @ angular.js:8289compositeLinkFn @ angular.js:7680publicLinkFn @ angular.js:7555$interpolate.compile @ angular-ui-router.js:4026invokeLinkFn @ angular.js:8789nodeLinkFn @ angular.js:8289compositeLinkFn @ angular.js:7680publicLinkFn @ angular.js:7555updateView @ angular-ui-router.js:3959(anonymous function) @ angular-ui-router.js:3921parent.$get.Scope.$broadcast @ angular.js:16311$state.transitionTo.$state.transition.resolved.then.$state.transition @ angular-ui-router.js:3311processQueue @ angular.js:14745(anonymous function) @ angular.js:14761parent.$get.Scope.$eval @ angular.js:15989parent.$get.Scope.$digest @ angular.js:15800parent.$get.Scope.$apply @ angular.js:16097done @ angular.js:10546completeRequest @ angular.js:10744requestLoaded @ angular.js:10685
angular.js:68 Uncaught Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.4.7/$rootScope/inprog?p0=%24digestREGEX_STRING_REGEXP @ angular.js:68beginPhase @ angular.js:16346parent.$get.Scope.$digest @ angular.js:15780(anonymous function) @ angular.js:16028completeOutstandingRequest @ angular.js:5507(anonymous function) @ angular.js:5784
The console.log in my exceptionOverride fires 7 times, then the exception is thrown (as expected) but then I also get a $digest already in progress error.
What am I doing wrong?