Specifications
a break statement and execution "falls through" to case 4. If expr is not 1, "two", 3 or 4 then
the default case will be matched and doDefaultAction() will be executed.
throw
try {
Statements;
throw "an exception";
}
catch ( e ) {
if ( e == "an exception" ) {
ExceptionStatements;
}
else {
OtherExceptionStatements
}
}
The throw keyword is used to raise user-defined exceptions.
Example:
function monthToName( i )
{
var IndexToMonth = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
if ( i < 0 || i > 11 ) {
throw "month number out of range";
}
else {
return IndexToMonth[ i ];
}
}
It is also possible to define a user-defined exception class and throw an object of that type,
example:
throw new AUserDefinedException( "month number out of range" );
See also try.
try
try {
Statements;
}
catch ( e ) {
}
try {
Statements;
}
finally {
}
The try keyword is used to identify a statement block for which exceptions will be caught. There
are two kinds of try block, try...catch and try...finally.
try...catch
If an exception occurs within a try...catch block, control is passed to the first catch block. If that
catch block does not accept the exception, control is passed on to the next catch block (if any)
and so on, until there are no more catch blocks, in which case the exception is passed up the
call chain until an enclosing catch block is found to accept it or if none accept it, the program
will terminate.
406
Enfocus Switch 10