How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 4-07- async-errors-try-catch.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create an async function, addBoosters, that throws some error:
async function addBoosters() { 
  throw new Error('Unable to add Boosters'); 
} 
  1. Create an async function, performGuidanceDiagnostic, that also throws an error:
async function performGuidanceDiagnostic (rocket) { 
  throw new Error('Unable to finish guidance diagnostic')); 
} 
  1. Create an async as the main function that calls addBosters and performGuidanceDiagnostic and handles the error:
 export async function main() { console.log('Before Check'); try { await addBosters(); ...

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.