var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>$exceptionHandler in AngularJs</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.7/angular-messages.js"></script>
<script>
var app = angular.module('exceptionApp', []);
app.provider({
$exceptionHandler: function() {
var errorHandler = function(ex) {
alert(ex);
//console.log(ex);
};
this.$get = function() {
return errorHandler;
};
}
});
app.controller('ExceptionCtrl',["$scope","$exceptionHandler", function($scope, $exceptionHandler) {
$scope.name = "Anil Singh";
//Throw error here using handler as function.
$exceptionHandler.handler('Throw error');
}]);
</script>
</head>
<body ng-app="exceptionApp" ng-controller="ExceptionCtrl">
<h1>Use of $exceptionHandler in AngularJs</h1>
<p>Hello {{name}}!</p>
<br>
<a href="http://www.code-sample.com/">click for more detail</a>
</body>
</html>
/* Put your css in here */