JavaScript Error Handling Interaction with Promises



Exceptions are to synchronous code what rejections are to promise-based asynchronous code. If an exception is thrown in a promise handler, its error will be automatically caught and used to reject the promise instead.

    .then(result => {
        throw new Error("I don't like five");
    .then(result => {"Promise resolved: " + result);
    .catch(error => {
        console.error("Promise rejected: " + error);


Promise rejected: Error: I don't like five

The async functions proposal—expected to be part of ECMAScript 2017—extends this in the opposite direction. If you await a rejected promise, its error is raised as an exception:

async function main() {
  try {
    await Promise.reject(new Error("Invalid something"));
  } catch (error) {
    console.log("Caught error: " + error);


Caught error: Invalid something