डाउनलोड पी.डी.एफ. ई-बुक्स
JS - Error Handling Throw

विवरण :

कोई विवरण नहीं है |


सोर्स कोड :

<html>
<head>
<script type="text/javascript">

var x=10;
var y=20;

function myfunction(){
try
{
if(x > y){
throw "alert1";
} 
else if(x < y){
throw "alert2";
}
else {
throw "alert3";
}
}
catch(err)
{
if(err == "alert1")
alert("x is greater than y");
if(err == "alert2")
alert("x is less than y");
if(err == "alert3")
alert("x is equal to y");
}
}

</script>
<body>

<button onclick="myfunction()"> Click Me </button>

</body>
</head>
</html>

आउटपुट :