JavaScript Basics -12 JavaScript error handling

Source: Internet
Author: User

One, JavaScript error handling


Error Handling Overview

-error, which refers to an unhealthy state in the program, which is called "Exception" or "error" in other programming languages. The interpreter creates and throws an error object for each error condition that contains the wrong description information

-ECMAScript defines six types of errors (Evalerror,rangeerror,referenceerror,syntaxerror,typeerror,urierror). In addition, you can use the error construction method to create a custom error object and throw the object with the throw statement

-By using the exception-handling statements provided by JS, you can capture the errors in a structured way, separating the exception handling code from the core business code, and ultimately allowing us to focus on writing the main business function code


Error Object

-The Error object is used to encapsulate the relevant description information for the exception

-The Error object has the following member properties

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/30/wKiom1b46AKDh5Y1AABYaBdlsFk553.png "title=" Web.png "alt=" Wkiom1b46akdh5y1aabyabdlsfk553.png "/>

-The Error object has the following member properties

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7E/2C/wKioL1b46N2Rjl-fAAAdgs9weis311.png "title=" Web.png "alt=" Wkiol1b46n2rjl-faaadgs9weis311.png "/>


Try/catch

-Use try...catch...finally in ECMAScript ... structure to perform exception handling, capturing error objects created and thrown by the system generation or program, and handling errors. The syntax is as follows:

try{//Here is the main business function code//main business function code may generate and throw error}catch (Error) {//Here is the code responsible for error handling}finally{ Here is the export statement, regardless of whether the error occurred or not to execute}


Summary: This chapter covers JavaScript error handling


This article from the "Technical Exchange" blog, declined reprint!

JavaScript Basics -12 JavaScript error handling

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.