Javascript Exception Processing (try... Catch... Finally)

Source: Internet
Author: User

1. users using the Mozilla Browser can view the errors found by the browser directly on the Javascript console under tools.

Ii. Use exception handling to catch JavaScript exceptions.
The following is an example of JavaScript exception handling.

VaR array = NULL;
Try {
Document. Write (array [0]);
} Catch (ERR ){
Document. writeln ("error name:" + err. Name + "");
Document. writeln ("error message:" + err. Message );
}
Finally {
Alert ("object is null ");
}

ProgramExecution Process

1. When array [0] is created, array is an empty object because array [0] is not created. If array [0] is called in the program, the object is null.
2. The catch (ERR) statement captures this exception and prints the Error Type through err. Name, and err. Message prints the error details.
3. Finally is similar to Java finally, and will be executed no matter whether exceptions exist.

We will summarize the information corresponding to the six values of error. Name:
1. evalerror: eval () is used and defined differently.
2. rangeerror: value out of bounds
3. referenceerror: Invalid or unrecognized reference value
4. syntaxerror: Syntax Parsing Error
5. typeerror: Incorrect operand type
6. urierror: The URI processing function is improperly used.

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.