繁体   English   中英

尝试/捕获冒泡澄清

[英]Try/catch bubbling clarification

如果我删除第二个 try/catch 块,考虑到 IIFE 前面是return ,那么 IIFE 中发生的异常是否会冒泡到第一个 try/catch 块?

我试图消除不必要的 try/catch 块并理解冒泡。

const run = (
  identifier: string
): Promise<{
  installationId: string;
}> =>
  new Promise(async (resolve, reject) => {
    try {
      const { installationId } = await getInstallation(identifier);

      await updateInstallation(installationId);

      resolve({
        installationId,
      });
    } catch (errorCode) {
      if (errorCode === "installationNotFound")
        return (async () => {
          try {
            const installationId = await insertInstallation(identifier);

            resolve({
              installationId,
            });
          } catch (errorCode) {
            reject(errorCode);
          }
        })();

      reject(errorCode);
    }
  });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM