Java Reference
In-Depth Information
catch(exception)
{
if (typeof(exception) == “string” && exception.charAt(0) == “!”)
{
alert(exception.substr(1));
document.form1.txtNum1.focus();
document.form1.txtNum1.select();
}
else
{
throw exception;
}
}
}
catch(exception)
{
switch (exception)
{
case “This page is not loaded within the correct frameset”:
alert(exception);
break;
default :
alert(“The following critical error has occurred \n” + exception);
}
}
}
The inner try...catch deals with user input errors. However, if the error is not a user input error
thrown by us, it is thrown for the outer catch statement to deal with. The outer catch statement has a
switch statement that checks the value of the error message thrown. If it's the error message thrown by
us because the calcfactorialtopframe.htm is not loaded, the switch statement deals with it in the
fi rst case statement. Any other error is dealt with in the default statement. However, there may well
be occasions when there are lots of different errors you want to deal with in case statements.
fi nally Clauses
The try...catch statement has a finally clause that defi nes a block of code that will execute whether
or not an exception was thrown. The finally clause can't appear on its own; it must be after a try block,
which the following code demonstrates:
try
{
ablurt(“An exception will occur”);
}
catch(exception)
{
alert(“Exception occurred”);
}
finally
{
alert(“Whatever happens this line will execute”);
}
Search WWH ::




Custom Search