DEV Community 👩‍💻👨‍💻

Discussion on: Migrating from promise chains to async-await and escaping the try catch hell

miketalbot profile image
Mike Talbot ⭐ • Edited on

Given your result requires a, b and c and would fail without all of them, why not write one catch handler?

async function heaven(){
   try {
      const a= await step1();
      const b= await step2(a);
      const c= await step3(b);
      return a + b + c;
   } catch(e) {
       // something like
       // throw new Error("Trouble in heaven")
       // or
       return 0
Enter fullscreen mode Exit fullscreen mode

Also your awesome function is probably missing the promise parameter