Created
April 25, 2018 08:29
-
-
Save philip-goh/eae41836c05424136c67f5df819b7519 to your computer and use it in GitHub Desktop.
Javascript promises and exception handling
This file contains 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
// Just a simple test to see how exception handling works in a promise. | |
function someFunc() { | |
return new Promise((fulfil, reject) => { | |
fulfil("This is from a promise"); | |
}); | |
} | |
someFunc() | |
.then(res => { | |
console.log(`Result: ${res}`); | |
}) | |
.then(() => { | |
console.log("In another then..."); | |
throw new Error("This is an error"); | |
}) | |
.then(() => { | |
console.log("Will never get here..."); | |
}) | |
.catch(err => { | |
console.log(`Caught error: ${err}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment