Created
June 12, 2014 10:23
-
-
Save sebdeckers/f0ca238325a858206013 to your computer and use it in GitHub Desktop.
Playing with Promise syntax
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
require('es6-shim'); | |
function doSomething() { | |
console.log('doSomething'); | |
return Promise.resolve(); | |
} | |
function doMore() { | |
console.log('doMore'); | |
return Promise.reject(Error('failed')); | |
} | |
function recover1() { | |
console.log('recover1'); | |
return Promise.reject(Error('failed')); | |
} | |
function recover2() { | |
console.log('recover2'); | |
return Promise.reject(Error('failed')); | |
} | |
doSomething() | |
.then(doMore) | |
.catch(function catch1(err) { | |
console.log('catch1'); | |
recover1() | |
throw new Error('error in the middle of error handling') | |
recover2() | |
}) | |
.catch(function catch2(err) { | |
console.log('catch2'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: