Skip to content

Instantly share code, notes, and snippets.

@krrg
Created July 22, 2015 17:00
Show Gist options
  • Save krrg/c7e7ea1f41ef27c6549a to your computer and use it in GitHub Desktop.
Save krrg/c7e7ea1f41ef27c6549a to your computer and use it in GitHub Desktop.
.then() and .catch() semantic comparison
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."
});
{
"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