Throw that error : throw « Language Basics « JavaScript DHTML






Throw that error

   
<HTML>
<HEAD>
<TITLE>Throw that error!</TITLE>
<SCRIPT>
function throwError(errString) {
   try {
      throw new Error (42, errString);
   }
   catch(e){
      alert("Error number: " + e.number + "; Description: " + e.description)
   }   
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="theForm">
Error text:
<INPUT type=text name=errText size=40>
<INPUT type=button name=btnThrow value="Throw it!" onClick="throwError(document.theForm.errText.value);">
</FORM>  
</BODY>
</HTML>

   
    
    
  








Related examples in the same category

1.Throws error in case of invalid data
2.Catch that error
3.Exception handling with try/catch