Errors and Promises

suggest change

Promises handle errors differently to synchronous or callback-driven code.

const p = new Promise(function (resolve, reject) {
    reject(new Error('Oops'));
});

// anything that is `reject`ed inside a promise will be available through catch
// while a promise is rejected, `.then` will not be called
p
    .then(() => {
        console.log("won't be called");
    })
    .catch(e => {
        console.log(e.message); // output: Oops
    })
    // once the error is caught, execution flow resumes
    .then(() => {
        console.log('hello!'); // output: hello!
    });

currently, errors thrown in a promise that are not caught results in the error being swallowed, which can make it difficult to track down the error. This can be solved using linting tools like eslint or by ensuring you always have a catch clause.

This behaviour is deprecated in node 8 in favour of terminating the node process.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Exception handling:
* Errors and Promises

Table Of Contents
1 npm
16 Exception handling
41 cli
43 grunt
59 Hack
64 ES6
67 Redis
69 MongoDB
86 MongoDB
87 Lodash
91 CORS
105 N-API
108 Require