Exception handling javascript
error:-
syntax
logical
run time
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function f1(){
var a=
document.getElementById('nm').value;
alert(a);
try{
if(a=="") throw "please fill this box";
else if(isNaN(a)) throw "please fill no";
else throw "";
}
catch(e){
document.getElementById('err').innerText=e;
}
finally
{
document.getElementById('nm').value="";
}
}
</script>
</head>
<body>
<input type="text" name="nm" id="nm">
<span id='err'></span>
<br/>
<button onclick="f1()">click</button>
</body>
</html>
2:----
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function f1(){
// console.log("good morning");
try{
a='';
if(a=="") throw "please fill this box";
}
catch(e){
// alert("good morning");
document.getElementById('msg')
.innerText=e;
}
}
// finally{
// alert('good morning');
// }
</script>
</head>
<body>
<span id='msg'></span>
<button onclick="f1()">click</button>
</body>
</html>
Comments
Post a Comment