Created
July 1, 2019 02:01
-
-
Save kunigami/95ee258353738151e0f2125fa8f05c04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function f() { | |
return Math.random() > 0.5 ? | |
Promise.resolve(10) : | |
Promise.reject(new Error('code x')); | |
} | |
async function g() { | |
try { | |
return await f(); | |
} catch (e) { | |
throw new Error('error: ' + e.message); | |
} | |
} | |
g() | |
.then(r => console.log(r)) | |
.catch(e => console.error(e)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment