Skip to content

Instantly share code, notes, and snippets.

@kunigami
Created July 1, 2019 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/95ee258353738151e0f2125fa8f05c04 to your computer and use it in GitHub Desktop.
Save kunigami/95ee258353738151e0f2125fa8f05c04 to your computer and use it in GitHub Desktop.
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