How to properly overwrite the exceptionHandler in angularjs?

For an app I'm using a skeleton that is very similar to https://github.com/angular/angular-seed.

I've tried something like this, in services.js:

'use strict'; /* Services */ angular.module('mApp.services', []). factory('$exceptionHandler', function () { return function (exception, cause) { alert(exception.message); } });

This doesn't do anything, it doesn't seem to overwrite the exceptionHandler.

If I try:

var mod = angular.module('mApp', []); mod.factory('$exceptionHandler', function() { return function(exception, cause) { alert(exception); }; });

It overwrite the whole app.

How can I properly overwrite the exceptionHandler if I am using a skeleton similar to the default angular app?


It's hard to know for certain without seeing the rest of your app, but I'm guessing angular.module('myApp').factory( ... will work. If you leave out the second parameter (,[]) angular will retrieve an existing module for further configuring. If you keep it angular will create a new module.


try this example


var myApp = angular.module('myApp', ['ng']).provider({ $exceptionHandler: function(){ var handler = function(exception, cause) { alert(exception); //I need rootScope here }; this.$get = function() { return handler; }; } }); myApp.controller('MyCtrl', function($scope, $exceptionHandler) { console.log($exceptionHandler); throw "Fatal error"; });


  • Why it happens - RelatedObjectDoesNotExist error caused by Model.clean()?
  • SQL: remove duplicate values from a select based on 2 fields
  • Handling PostTooLargeException in Laravel 5.5
  • Is it impossible to show forms when handling a AppDomain.CurrentDomain.UnhandledException?
  • using global exception handeling messes up DelegatingHandler
  • C++ - catch all exceptions?
  • Dependency injection without Ninject
  • How to make HttpWebRequest async
  • Zend framework 2 : Add different authentication adapter for two different modules
  • Lua: Line breaks in strings
  • Updating Dojo provide
  • Is there a way to save the selected text and highlight it again once the page is refreshed?
  • Execute scripts AJAX returns
  • How to use JavaScript to determine whether a file exists in a directory?
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Retrieve list of sent friend requests from friend_request FQL table
  • SplFileObject error failed to open stream: No such file or directory
  • Functions in global context
  • D3 nodes and links from JSON with nested arrays of children
  • NHibernate Validation Localization with S#arp Architecture
  • FileReader+canvas image loading problem
  • How can I send an e-mail from a vbs script
  • Accessing IRQ description array within a module and displaying action names
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • javascript inside java/jsp code
  • How can I use Kendo UI with Razor?
  • Compare two NSDates in iPhone
  • How to format a variable of double type
  • Android Studio and gradle
  • Getting Messege Twice Using IMvxMessenger
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Is there any way to bind data to data.frame by some index?
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • How can i traverse a binary tree from right to left in java?
  • How can I use `wmic` in a Windows PE script?
  • Net Present Value in Excel for Grouped Recurring CF
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?