Created
July 22, 2015 17:00
-
-
Save krrg/c7e7ea1f41ef27c6549a to your computer and use it in GitHub Desktop.
.then() and .catch() semantic comparison
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
var when = require('when'); | |
var B = when(777); | |
// Using the .catch after .then | |
B.then(function(result) { | |
throw "There was an error in our function!"; | |
}) | |
.catch(function(err) { | |
console.log(err); | |
}) | |
// Using the second parameter of .then() | |
var C = when(777); | |
C.then(function(result){ | |
throw "Yeah there was an error in here."; | |
}, function(err) { | |
console.log(err); | |
}) | |
// Using .catch before .then | |
var D = when(777); | |
D.catch(function(err){ | |
console.log(err); | |
}) | |
.then(function(result){ | |
throw "There was a big time error right here." | |
}); |
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
{ | |
"name": "promises_test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"when": "^3.7.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment