The first common sense is that, in the browser to execute the JS script, when there is a script error, and you do not manually catch the exception, he will appear under the browser yellow exclamation mark, which is normal, this is not the most important, the most important thing, the following error line of all JS code will be stopped execution, This is what we do not want to see, so say, for their own writing, a doubt of the script or the exception to capture better.
1 Clear yellow exclamation mark:
Copy Code code as follows:
Window.onerror={return true;} It's just that the surface clears the error, but the JS code will be stopped
2 A code snippet that is prone to error and that is prone to compatibility issues plus try ... Catch
Copy Code code as follows:
try{
var a= "Hello World";
Document. Write (a);
}
catch (e) {
//.. What you have to do when you have an exception
}