nodejs / promises

Promises Working Group Repository
107 stars 11 forks source link

Glossary Executor / Resolver immediate rejection explanation #28

Closed pspi closed 8 years ago

pspi commented 8 years ago

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()
ljharb commented 8 years ago

You handled it with .catch - the example lacks a .catch.

pspi commented 8 years ago

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.