How to do it...

  1. Open your command-line application and navigate to your workspace.
  2.  Create a new folder named 3-07-handle-errors-promise-catch.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  1. Create a main.js file with a main function that creates an object named rocket:
export function main() { 
 
  console.log('Before promise created'); 
 
  const rocket = {}; 
 
  console.log('After promise created'); 
} 
  1. Create a function addBoosters that throws an error:
function addBoosters (rocket) { 
  throw new Error('Unable to add Boosters'); 
} 
  1. Create a function performGuidanceDiagnostic that returns a promise that rejects an error:
function performGuidanceDiagnostic (rocket) { return new Promise(function (resolve, reject) { ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.