//Catch is the method used when your promise has been rejected.
//It is executed immediately after a promise's reject method is called.
//Here’s the syntax:
myPromise.catch(error => {
// do something with the error.
});
//error is the argument passed in to the reject method.
// returns a promise
let countValue = new Promise(function (resolve, reject) {
reject('Promise rejected');
});
// executes when promise is resolved successfully
countValue.then(
function successValue(result) {
console.log(result);
},
)
// executes if there is an error
.catch(
function errorValue(result) {
console.log(result);
}
);