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

Source: Internet
Author: User
From: http://www.ntsky.com/xml/article/3.xml

When writing JavaScript, do we worry about finding JavaScript errors? But there are two ways to handle JavaScript errors.

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. Array [0] is an empty object because array [0] is not created. If array [0] is called in the program, an exception occurs when 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 can be executed regardless of exceptions.

We will summarize the information corresponding to the six values of error. Name:

    1. Evalerror: eval () usage and definition are inconsistent
    2. Rangeerror: value out of bounds
    3. Referenceerror: an invalid or unrecognized reference value
    4. Syntaxerror: Syntax Parsing Error
    5. Typeerror: Incorrect operand type
    6. Urierror: The URI processing function is improperly used.

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.