Catch an error (IE) : Error « Development « JavaScript Tutorial






<HTML>
<HEAD>
   <TITLE>Catch that error!</TITLE>
<SCRIPT>
function catchError(errString) {
   try {
      try {
            throw new Error (42, "errString is 42!");
      }
      catch(e) {
         if (e.number == 42)
            return (e.description + " Got this one!");
         else
            throw e; 
      } 
   }
   catch (e){
      return(e.description + " This one not handled here!");
   } 
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="theForm">
<INPUT type=text name=errText size=40 value="42">
<INPUT type=button 
       name=btnThrow 
       value="Catch it!" 
       onClick="alert(catchError(document.theForm.errText.value));">
</FORM>  
</BODY>
</HTML>








4.6.Error
4.6.1.Try catch user exception
4.6.2.Use Error
4.6.3.Throw out an Error
4.6.4.Catch an error (IE)