function doubleAfter2seconds(num) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(2 * num)
reject('我就是想要錯')
}, 2000);
} )
}
async function timeout() {
await doubleAfter2seconds(45).catch(err=>{
console.log(err)
});
console.log('hello world')
return 'hello world'
}
timeout();
console.log('雖然在後面,但是我先執行');
僅爲個人學習記錄