First of all, a common sense is that when the browser executes the JS script, when a script error occurs and you do not manually catch the exception, a yellow exclamation mark will appear under the browser. This is normal, and this is not the case. The most important thing is that all JS code below the error line will stop executing. This is what we don’t want to see. Therefore, for scripts written by yourself that are uncertain, it is better to add exception capture. .
1 Clear the yellow exclamation mark:
Copy code The code is as follows:
window.onerror= {return true;} //This only clears the error on the surface, but the JS code will be stopped
2 Add try..catch
Copy the code for code segments that are prone to errors and compatibility issues. The code is as follows:
try{
var a="hello world";
document.Write(a);
}
catch (e){
//..What you have to do when an exception occurs
}
http://www.bkjia.com/PHPjc/765161.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/765161.htmlTechArticleFirst of all, a common sense is that when the browser executes the JS script, when a script error occurs, and you do not do it manually When an exception is captured, a yellow exclamation mark will appear under the browser...