xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

ECMAScript proposal: Error cause (chaining errors) All In One

ECMAScript proposal: Error cause (chaining errors) All In One


function readFiles(filePaths) {
  return filePaths.map(
    (filePath) => {
      try {
        const text = readText(filePath);
        const json = JSON.parse(text);
        return processJson(json);
      } catch (error) {
        // (A)
      }
    });
}

throw new Error(error info =, {cause: error});


function readFiles(filePaths) {
  return filePaths.map(
    (filePath) => {
      try {
        // ···
      } catch (error) {
        // ✅
        throw new Error(`While processing ${filePath}`, {cause: error});
      }
    });
}


refs

https://2ality.com/2021/06/error-cause.html



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-06-24 17:39  xgqfrms  阅读(114)  评论(1编辑  收藏  举报