Skip to content

Instantly share code, notes, and snippets.

@welll
Created December 10, 2017 16:46
Show Gist options
  • Save welll/fa4e6d53e1fd77eb8fccd22e687d656d to your computer and use it in GitHub Desktop.
Save welll/fa4e6d53e1fd77eb8fccd22e687d656d to your computer and use it in GitHub Desktop.
let myAsyncFunctionThatReturnsPromise = new Promise((resolve, reject) => {
setTimeout(function(){
resolve("Success!")
}, 2500)
})
let foo1 = Promise.resolve()
.then(function(){ callUndefinedFunction() })
.catch((e)=> console.log(`Error: ${e}`))
let foo2 = Promise.reject('Promise was Rejected')
.then(function(){ throw Error('x') })
.catch((e)=> {
console.log(`Error: ${e}`)
callUndefineFunctionHereAtCathcBlock()
})
myAsyncFunctionThatReturnsPromise.then((resolvedValue) => {
console.log(`resolvedValue: ${resolvedValue}`)
}).catch( (error) => {
console.log(`resolvedValue: ${resolvedValue}`)
})
new Promise((_, reject) => reject(new Error('woops'))).
catch(error => {
// Will not execute
console.log('caught', error.message);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment