Angularjs Examples

AJS Examples

AngularJS $exceptionHandler Service

The AngularJS $exceptionHandler is used to handle any uncaught exception in angular expressions. The default implementation of error is using $log.error in the browser console. It allows overriding the default exception handler behaviour by redefining in a factory.


$exceptionHandler(exception, [cause]);

AngularJS $exceptionHandler Service Example

<!DOCTYPE html>        
<head> <!-- -->        
<title>AngularJS $exceptionHandler Example</title>        
<script SRC=""></script>   
    var app = angular.module("ExceptionInitialization",[]);
			return function (exception, cause){
				alert('Error occurred');
		app.controller("ExceptionHandlerController",function ($scope) {
          $scope.error = "";
          $scope.ThrowError = function()
				throw new Error('exception occurre');
<body style="background-color:#DDE4E9;font-family:arial;" ng-app="ExceptionInitialization">        
  <fieldset style="background-color:#DDE4E9;">          
    <legend>AngulerJS $exceptionHandler Example</legend>          
<div ng-controller="ExceptionHandlerController">  
	<p><button ng-click="ThrowError()">Throw Error</button></p>
See Live Example