promise can handle exceptions, so what"s the difference between them in handling exceptions?
Promise.reject("error").then(()=> {}, val=> {
console.log(val);
});
Promise.reject("error").catch(val=> {
console.log(val);
});
promise can handle exceptions, so what"s the difference between them in handling exceptions?
Promise.reject("error").then(()=> {}, val=> {
console.log(val);
});
Promise.reject("error").catch(val=> {
console.log(val);
});
first correct a misunderstanding:
who says reject is used to handle exceptions-- reject is used to throw exceptions, and catch is used to handle exceptions.
compared to the traditional try catch writing, reject is equivalent to throw
then reject is the method of Promise, and catch is the method of Promise instance:
there is a mistake in the first function of then, which can be captured by the later catch, but not by the second function written to then.