简体   繁体   中英

AngularJS - Disable $exceptionHandler

I don't want $exceptionHandler to handle any exceptions - I want them to propegate up to the browser (primarily for IE testing in Visual Studio).

I'd tried overriding $exceptionHandler and simply rethrowing the error, which gives me the 10 iterations of $digest error (which makes sense).

How do I shut it off completely?

EDIT

Unfortunately rethrowing the error doesn't solve the issue - IE only knows the error from the rethrow and not from source.

After some research, this isn't possible. Angular catches their errors and then calls the exception handler explicitly - in many cases it does not just let the error propagate.

According to the documentation , it's possible:

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.

Try throwing the exception inside a window.setTimeout (not $timeout ) delayed execution, this would allow you to escape the $digest black hole. But not sure it will preserve the stack-trace in IE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM