Last active
March 5, 2019 10:20
-
-
Save gskachkov/d2ce416418139c6b472e7aed88ae6789 to your computer and use it in GitHub Desktop.
Await rejected promise
This file contains hidden or 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
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