Exception handling with try/catch : throw « Language Basics « JavaScript DHTML






Exception handling with try/catch

   
<HTML>
<HEAD>
<TITLE></TITLE>

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function getMonthName (monthNumber) {
     throw "InvalidMonthNumber"
}
try {
    alert(getMonthName(13))
}
catch (exception) {
    alert("An " + exception + " exception was encountered.  Please contact the program vendor.")

}



</SCRIPT>
<BODY>

</BODY>
</HTML>

   
    
    
  








Related examples in the same category

1.Throws error in case of invalid data
2.Catch that error
3.Throw that error