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