How can I know the promise function calling is caught exception or not

I have two simple function as below, one is callback and another one is Promise, in call back function, I can know whether the function caller caught the exception, but in the promise function I don’t know how to handle it.

First one

  let call = function(a,b,success,fail){
      if(a==b){
         success();
       }
      else{
         if(fail){
           fail();
         }
         else{
           alert("a is not equal b");
         }
       }
  }

The second one

   let call = function(a,b){
     return new Promise(resolve,reject){
        if(a==b){
          resolve();
        }
        else{
           //I want to code here, if the call is not catch error, 
           //the system alert("a is not equal b"), otherwise call the reject.           
        }
     }
   }

88 thoughts on “How can I know the promise function calling is caught exception or not”

Leave a Comment