Javascript Exception Handling (try... catch... finally)
The following information is from "ntsky's blog"
P.s.
I recently started to study Ajax technology, which uses JavaScript error capture! I found this article well written on the Internet and added it to my favorites!
// ================================================ ======================================
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 ");
}
Program Execution 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.
// ================================================ ======================================