Improve this Doc View Source $exceptionHandler

  1. service in module ng

Any uncaught exception in angular expressions is delegated to this service. The default implementation simply delegates to $log.error which logs it into the browser console.

In unit tests, if angular-mocks.js is loaded, this service is overridden by mock $exceptionHandler which aids in testing.

Example:

angular.module('exceptionOverride', []).factory('$exceptionHandler', function () {
  return function (exception, cause) {
    exception.message += ' (caused by "' + cause + '")';
    throw exception;
  };
});

This example will override the normal action of $exceptionHandler, to make angular exceptions fail hard when they happen, instead of just logging to the console.

Dependencies

Usage

$exceptionHandler(exception, [cause]);

Arguments

Param Type Details
exception Error

Exception associated with the error.

cause
(optional)
string

optional information about the context in which the error was thrown.

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.2.32/docs/api/ng/service/$exceptionHandler