<script type="text/javascript">
var numerator = Number(prompt("enter numerator"));
var denominator = Number(prompt("enter denominator"));
try {
if( denominator == 0){
throw{
error: "divided by 0",
message: " customize error msg "
}
}
else {
document.write("REsult is "+ (numerator/denominator));
}
}
catch (e){
console.log(e) // [Object object]
console.log(e.error, e.message) // custome Error Message
}
finally
{
// if there is exception or not finally block will execute
console.log("finally block");
}
</script>
var numerator = Number(prompt("enter numerator"));
var denominator = Number(prompt("enter denominator"));
try {
if( denominator == 0){
throw{
error: "divided by 0",
message: " customize error msg "
}
}
else {
document.write("REsult is "+ (numerator/denominator));
}
}
catch (e){
console.log(e) // [Object object]
console.log(e.error, e.message) // custome Error Message
}
finally
{
// if there is exception or not finally block will execute
console.log("finally block");
}
</script>
No comments:
Post a Comment