Skip to content

Instantly share code, notes, and snippets.

@gskachkov
Last active March 5, 2019 10:20
Show Gist options
  • Save gskachkov/d2ce416418139c6b472e7aed88ae6789 to your computer and use it in GitHub Desktop.
Save gskachkov/d2ce416418139c6b472e7aed88ae6789 to your computer and use it in GitHub Desktop.
Await rejected promise
var foo = async function () {
try {
await Promise.reject('error in promise');
} catch (e) {
console.log('caught error:', e);
}
};
foo().then(
result => console.log('success-', result),
error => console.log('error handler-', error)
);
/* Output */
// caught error: error in promise
// success- undefined
var boo = async function () {
await Promise.reject('error in promise');
};
boo().then(
result => console.log('success-', result),
error => console.log('error handler-', error)
);
/* Output */
// error handler- error in promise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment