<html>
<head>
<title>Using throw in a try..catch statement</title>
<script language="JavaScript">
<!--
function myErrorHandler(data){
try{
if(data == "string"){
throw "E0";
}else{
throw "E1";
}
}catch(e) {
if(e == "E0"){
return("Error (" + e + "): Entry must be numeric.");
}else{
return("Error (" + e + "): Entry must be numeric.");
}
}
}
function processData(form){
if(isNaN(parseInt(form.myText.value))){
alert(myErrorHandler("string"));
}else{
alert("You have correctly entered a number");
}
}
-->
</script>
</head>
<body>
<form name="myForm">
Please enter a number:
<input type=TEXT size=10 value="" name="myText">
<input type=BUTTON value="Process" name="myButton" onClick='processData(this.form)'>
</form>
</body>
</html>
|