Glossary Executor / Resolver immediate rejection explanation
pspi opened this issue · 2 comments
In the Glossary the Executor / Resolver section states that throwing inside new Promise(...)
is considered an unhandled rejection. Is this really correct?
Catches all errors thrown. If an error is caught, the returned promise will be rejected. Because it starts life as a rejected promise with no children, it will immediately hit the OnUnhandledRejection callback.
This test would suggest otherwise, Node 6.0.0.
new Promise((resolve, reject) => {
throw new Error();
}).catch((e) => {
console.log('.catch()')
});
$ node test.js
.catch()
You handled it with .catch
- the example lacks a .catch
.
Isn't it describing Executors in general, not the example, doesn't the example come only later?
When I read the Glossary text, it read like it was presented as universal truth: "throwing in Executor always leads to unhandled rejection since it's run synchronously and starts life with no children - therefore the rejection has no possibility to be handled". Which is kind of.. yikes.
Oh well, I'm sure this Glossary is not that widely used, but I just wanted clarify this.