Closed2
Promise が reject したときに複数の catch で構えていた場合の挙動

const throws = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error("out!"));
}, 2000);
});
}
(async() => {
const promise = throws();
try {
await promise;
} catch (e) {
console.log("error 1")
}
try {
await promise;
} catch (e) {
console.log("error 2")
}
})()
// error 1
// error 2
ちゃんとどっちも引っかかってくれた
このスクラップは2024/09/10にクローズされました