Try/catch for async/await function in Nodejs with Mysql

Hi everyone, I’m new to Nodejs and I don’t know how to catch exception in this case:
I have an error in my query but catch cannot log the error and continue to do other things until the app crash (I use module mysql2).

try {
      var xx = await connection.execute(`UPDAT Products SET quantity=(SELECT * FROM (SELECT quantity FROM Products WHERE id=${id[index]}) AS quantity) - ${quantities[index]} WHERE id=${id[index]};`);
}
catch (err) {
      console.log(err);
}

Could you please point out for me if I miss something? Thank you very much

async/await is just syntactic sugar built over promises, you need to check if the underlying promise is truly handling rejections, as that rejection handling is what would be passed down to your catch block.

1 Like

Thanks for your suggestion @Dereje1. I intent to convert my function back to promise style in order to handle exception. Again, I very appreciate your help!