亲爱的参与者,请告诉我解决方案。
在此代码块中,catсh方法完美地捕获了异常:
const myPromise = new Promise(() => {
throw new Error(`Oops! Threw an exception`);
});
// We catch the exception in the method `catch`.
myPromise
.catch((error) => console.log(error.message));
并且在此块中,不会调用catсh方法:
сonst TIMEOUT = 1000;
const mySecondPromise = new Promise((resolve, reject) => {
setTimeout(() => {
throw new Error(`Error in asynchronous function`);
},
TIMEOUT
);
});
mySecondPromise
.catch(() => console.log(`This code will not be executed`));
请说明:
谢谢大家的回答!
尊敬的与会者,请告诉我解决方案。在此代码块中,catсh方法完美地捕获了以下异常:const myPromise = new Promise(()=> {throw new Error(`Oops!Throw a ...