[英]How to tell whether a Javascript error is 'blocking'?
Is there such a thing as blocking vs non blocking Javascript errors? 有阻塞与不阻塞Javascript错误之类的东西吗?
What I mean is that I've seen my site report some errors, but the process involved still completes successfully (as far as I can tell). 我的意思是,我已经看到我的网站报告了一些错误,但是所涉及的过程仍然成功完成(据我所知)。 These errors include: TypeError: undefined is not an object (evaluating 'e.nodeName.toLowerCase') TypeError: e.nodeName is undefined (these are always from my general JQuery library file)
这些错误包括:TypeError:未定义不是对象(正在评估'e.nodeName.toLowerCase')TypeError:e.nodeName是未定义(这些总是来自我的常规JQuery库文件)
These are what I mean by 'non-blocking' errors, since the scripts involved seem to complete successfully. 这些就是我所说的“非阻塞”错误,因为所涉及的脚本似乎已成功完成。
If there is such a thing as blocking v non-blocking, what is the correct terminology for it, and how can I tell the difference between the 2 (eg so that I can prioritise investigating blocking errors)? 如果存在阻止v非阻止之类的事情,那么正确的术语是什么,如何区分两者之间的区别(例如,以便可以优先研究阻止错误)?
Thanks 谢谢
Whenever 每当
throw Error;
The exception bubles up the function stack. 异常使函数堆栈失效。 If it reaches the end of it, it throws an uncaught (=unexpected) exception.
如果到达末尾,则会引发未捕获 (=意外)异常。 This halts the complete program as its unlikely to work properly anymore.
由于无法继续正常工作,因此这将终止整个程序。
However it can be catched (=expected exception): 但是可以捕获它(=预期的异常):
try{
someerrorproducingfunc();
//continue after success
}catch(e){
//continue after error
console.error(e);
}
//continue after error+success
So the code proceeds ( leaving out the continue after sucess part). 因此,代码继续执行( 成功后保留继续部分)。 However, if you use console.error it logs sth that looks like an error.
但是,如果使用console.error,它会记录看起来像错误的东西。
ressource: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/throw 资源: https : //developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/throw
Note that Error is just an object constructor in js: 请注意, Error只是js中的对象构造函数:
new Error("test");
While throw throws an exception ... 当throw抛出异常时 ...
No. All un-caught error are blocking, they will end the execution of the entire call stack. 否。所有未捕获的错误都将被阻止,它们将结束整个调用堆栈的执行。 However, an error that happens after various operation will not revert back to a situation like before.
但是,在各种操作之后发生的错误不会恢复到以前的情况。 Making an AJAX call, and then having an undefined error will not cancel the call for example.
例如,进行AJAX调用,然后发生未定义的错误不会取消该调用。 Demo:
演示:
(function () { "use strict"; let a = 5; console.log(a); // 5 setTimeout(function () { console.log(a); // 10 // will execute because it is a fresh stack // the variable a is 10 despite and not 12 because it happened after }, 250); const withError2 = function () { a = 10; axz = 2; // Error a = 12; // never executes because it comes after the error } withError2(); console.log(a); // never executes because it comes after the error }());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.