Skip to content

Instantly share code, notes, and snippets.

@solominh
Last active January 24, 2017 01:36
Show Gist options
  • Save solominh/43fdc08452df320effca1a95b1e79908 to your computer and use it in GitHub Desktop.
Save solominh/43fdc08452df320effca1a95b1e79908 to your computer and use it in GitHub Desktop.
var test = () => {
new Promise((resolve, reject) => {
resolve(undefined); // Will call then
}).then(() => {
console.log("Then");
}).catch(() => {
console.log("Catch");
})
}
var test1 = () => {
new Promise((resolve, reject) => {
resolve(somethingNotDeclareYet); // Exception inside resolve => will call catch
}).then(() => {
console.log("Then");
}).catch(() => {
console.log("Catch");
})
}
var test2 = () => {
new Promise((resolve, reject) => {
resolve(Promise.reject()); // Will call catch
}).then(() => {
console.log("Then");
}).catch(() => {
console.log("Catch");
})
}
var test3 = () => {
var doSomething = () => {
throw new Error('Error')
}
new Promise((resolve, reject) => {
resolve(doSomething()); // Will call Catch
}).then(() => {
console.log("Then");
}).catch(() => {
console.log("Catch");
})
}
var test4 = () => {
// All 3 promises will call catch
var promise1 = Promise.resolve(Promise.reject())
.catch((err) => {
console.log(err); //undefined
});
var promise2 = Promise.resolve().then(function () {
return Promise.reject();
}).catch((err) => {
console.log(err); //undefined
});
var promise3 = Promise.reject().catch(function () {
return Promise.reject();
}).catch((err) => {
console.log(err); //undefined
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment