exception catch in js

1. Exception: When an error occurs in js, the program stops running
. 2. Exception throwing: When an exception occurs, an error message is generated for the exception
. 3. Exception capture:
      try{
      Exception code block
      }catch(err{
                  Error message processing
                 }
Example:
function damo(){
   try{
     alert(str);//str is not declared
    }catch(err){
          alert(err);
         }
 }


4.Throw Statement: Create a custom error
Example :
function demo(){
 try{
   var e=document.getElementById("txt").value
   if(e==" "){
     throw "Please enter"
       }
   }catch{}
}


5.finally: whether the try statement is executed or not, finally will always be executed
6. Methods of terminating try statement 1) Normal termination, execute the last statement of the statement block 2) Terminate by break, continue, return statement 3) Throw an exception, The exception is caught by the catch clause 4) An exception is thrown, the exception is not caught and continues to propagate upwards

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326699611&siteId=291194637