「JavaScript」asyncとthrow文で例外をスローするサンプル
書式
関数名()
.then(xxx)
.catch(xxx)
使用例
<script>
async function funcA() {
throw new Error("AA");
}
funcA()
.then((tar) => {
console.log("BB");
})
.catch((tar) => {
console.log(tar);
});
</script>
<script>
async function funcA() {
throw new Error("AA");
}
funcA()
.then((tar) => {
console.log("BB");
})
.catch((tar) => {
console.log(tar);
});
</script>
<script> async function funcA() { throw new Error("AA"); } funcA() .then((tar) => { console.log("BB"); }) .catch((tar) => { console.log(tar); }); </script>
実行結果
Error: AA
at funcA (<anonymous>:3:11)
at <anonymous>:5:3
at submitTryit (tryit.asp?filename=tryjs_default:588)
at HTMLButtonElement.onclick (tryit.asp?filename=tryjs_default:460)