1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
const getLastName = () => { return new Promise((resolve, reject) => { resolve("田中"); reject("LastNameの取得に失敗しました"); }); } const getFirstName = () => { return new Promise((resolve, reject) => { reject("FirstNameの取得に失敗しました"); resolve("太郎"); }); } const getAge = () => { return new Promise((resolve, reject) => { resolve(23); reject("Ageの取得に失敗しました"); }); } const onlyReturn = args => args; const main = async() => { const lastName = await getLastName().catch(onlyReturn); const firstName = await getFirstName().catch(onlyReturn); const age = await getAge().catch(onlyReturn); console.log("lastName : " + lastName); console.log("firstName : " + firstName); console.log("age : " + age); }; main(); |
1 2 3 |
lastName : 田中 firstName : FirstNameの取得に失敗しました age : 23 |