// ES2022
function readFiles(filePaths) {
return filePaths.map(
(filePath) => {
try {
// ···
} catch (error) {
throw new Error(
`While processing ${filePath}`,
{cause: error}
);
}
});
}
// For more: https://2ality.com/2021/06/error-cause.html
asyncFunc().catch(
// catch error and do something
)