Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created June 4, 2015 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajcrites/941c8ed3e61d731cdbef to your computer and use it in GitHub Desktop.
Save ajcrites/941c8ed3e61d731cdbef to your computer and use it in GitHub Desktop.
Promise.resolve(process.hrtime())
.then(returnAPromise)
.then(returnAValue)
.then(returnAPromise)
.then(throwAnException)
.catch(handleExceptionAndReturnPromise)
.then(returnAPromise)
.then(throwAnException)
.catch(handleFinalException)
function returnAPromise(value) {
console.log(value);
return Promise.resolve(process.hrtime());
}
function returnAValue(value) {
console.log(value);
return process.hrtime();
}
function handleFinalException(error) {
console.log("all done", error);
}
function throwAnException(value) {
console.log(value, "about to throw!");
throw "exception thrown!";
}
function handleExceptionAndReturnPromise(error) {
console.log(error);
return Promise.resolve(process.hrtime());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment