简体   繁体   English

AngularJS - 禁用$ exceptionHandler

[英]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). 我不希望$ exceptionHandler处理任何异常 - 我希望它们能够推进到浏览器(主要用于Visual Studio中的IE测试)。

I'd tried overriding $exceptionHandler and simply rethrowing the error, which gives me the 10 iterations of $digest error (which makes sense). 我试过覆盖$ exceptionHandler并简单地重新抛出错误,这给了我10次迭代$ digest错误(这是有意义的)。

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. 不幸的是,重新抛出错误并没有解决问题 - IE只知道重新抛出的错误,而不是来自源。

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. Angular捕获它们的错误,然后显式调用异常处理程序 - 在许多情况下,它不仅仅是让错误传播。

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. 此示例将覆盖$ exceptionHandler的正常操作,以使角度异常在发生时更加失败,而不是仅仅记录到控制台。

Try throwing the exception inside a window.setTimeout (not $timeout ) delayed execution, this would allow you to escape the $digest black hole. 尝试在window.setTimeout (不是$timeout )延迟执行中抛出异常,这将允许你逃避$digest黑洞。 But not sure it will preserve the stack-trace in IE. 但不确定它是否会保留IE中的堆栈跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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