JavaScript exception handling statement _ javascript skills

Source: Internet
Author: User
Considering that JS errors are much more likely to be generated than the code on the server, and it is difficult to find and correct them, JS code must have exception handling and global processing. Errors are inevitable during the running of the program, and the running results after errors are often incorrect. Therefore, programs with errors during running are forcibly aborted. Running errors are collectively referred to as exceptions. in order to get a chance to handle errors, JavaScript provides exception handling statements. Include try-catch, try-catch-finally, and throw.

Try-catch statement

try{tryStatements}catch(exception){catchStatements}

Parameter description:
TryStatements: required. The sequence of statements that may cause errors.
Exception: required. Any variable name used to reference the error object when an error occurs.
CatchStatements: Optional. Error handling statement, used to handle errors in tryStatements.
During encoding, statements that may cause errors are often written into the curly brackets of the try block and the catch block after the try block is used to handle errors. The Error message is contained in an Error object, which can be accessed through reference of exception. Based on the error information in the error object, determine if the error is handled.

Related Article

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.