Last active
January 3, 2016 10:39
-
-
Save ohgyun/8451170 to your computer and use it in GitHub Desktop.
Promises Error 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
var p = function () { | |
var d = Q.defer(); | |
d.reject(); | |
return d.promise; | |
}; | |
# Case 1 | |
p() | |
.then(function () { | |
console.log('A'); | |
}, function () { | |
console.log('B'); | |
}); | |
//--> B | |
# Case 2 | |
P() | |
.then(function () { | |
console.log('A'); | |
}) | |
.fail(function () { | |
console.log('B'); | |
}); | |
//--> B | |
# Case 3 | |
p() | |
.then(function () [ | |
console.log('A'); | |
}) | |
.fail(function () { | |
console.log('B'); | |
}) | |
.then(function () { | |
console.log('C'); | |
}); | |
//--> B, C | |
# Case 4 | |
p() | |
.then(function () { | |
console.log('A'); | |
}) | |
.fail(function () { | |
console.log('B'); | |
}) | |
.fail(function () { | |
console.log('C'); | |
}) | |
.then(function () { | |
console.log('D'); | |
}); | |
//--> B, D | |
# Case 5 | |
p() | |
.fail(function () { | |
console.log('A'); | |
}) | |
.then(function () { | |
console.log('B'); | |
}) | |
.fail(function () { | |
console.log('C'); | |
}) | |
.then(function () { | |
console.log('D') | |
}); | |
//--> A, B, D | |
# Case 6 | |
p() | |
.then(function () { | |
console.log('A'); | |
}) | |
.then(function () { | |
console.log('B'); | |
}) | |
.then(function () { | |
console.log('C'); | |
}) | |
.fail(function () { | |
console.log('D'); | |
}); | |
//--> D | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment