View source Improve this doc

$exceptionHandler

service in module ng

Description

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:

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

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

  • $log

Usage

  1. $exceptionHandler(exception[, cause]);

Parameters

ParamTypeDetails
exceptionError Exception associated with the error.
cause (optional) string optional information about the context in which the error was thrown.