An Exception Handling Example : Error Exceptions : Development JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Development » Error Exceptions »

 

An Exception Handling Example



<HTML>
<HEAD><TITLE>Exception Test</TITLE></HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function primeTest(n) {
 document.write("Testing "+n+": ")
 try {
  if(n < || n > 20
      throw "It's out of range"
  for(var i = 2; i < n; ++i){
     if(n % i == 0
        throw "It's divisible by " + i
  }
  document.writeln("It's prime.<BR>")
 }
 catch (exception) {
  document.writeln(exception+".<BR>")
 }
}
--></SCRIPT>
<BODY>
<P>This script only works with Internet Explorer 5, Navigator 6, or later browsers.</P>
<SCRIPT LANGUAGE="JavaScript"><!--
for(i = 0; i <= 21; ++i) {
 primeTest(i)
}
--></SCRIPT>
</BODY>
</HTML>
           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Development
» Error Exceptions