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
- 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.
- The catch (ERR) statement captures this exception and prints the Error Type through err. Name, and err. Message prints the error details.
- 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:
- Evalerror: eval () usage and definition are inconsistent
- Rangeerror: value out of bounds
- Referenceerror: an invalid or unrecognized reference value
- Syntaxerror: Syntax Parsing Error
- Typeerror: Incorrect operand type
- Urierror: The URI processing function is improperly used.