Last active
August 21, 2017 21:09
-
-
Save timfulmer/e0f8de74298e296eedad813ba8beda9d to your computer and use it in GitHub Desktop.
Promises and error handling
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
'use strict'; | |
function promiseThatThrows(){ | |
return new Promise((resolve,reject) => { | |
throw new Error('!!This needs to be handled!!'); | |
}); | |
} | |
function correctNestedErrorHandling(){ | |
return new Promise((resolve,reject) => { | |
return promiseThatThrows() | |
.catch((err) => { | |
reject(err); | |
}); | |
}); | |
} | |
function hideError1(){ | |
return new Promise((resolve,reject) => { | |
return promiseThatThrows(); | |
}); | |
} | |
function hideError2(){ | |
return new Promise((resolve,reject) => { | |
return promiseThatThrows() | |
.catch((err) => { | |
throw err; | |
}); | |
}); | |
} | |
hideError1() | |
.catch((err) => { | |
console.log('This is not caught!!',err); | |
}); | |
hideError2() | |
.catch((err) => { | |
console.log('This is not caught!!',err); | |
}); | |
correctNestedErrorHandling() | |
.catch((err) => { | |
console.log('Correctly handled error',err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment