JS Exception Handling Try ... The role of Catch statement and instance _php instance

Source: Internet
Author: User
Tags exception handling

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

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.