Electron应用程序在调用autoUpdater.CheckForUpdate时崩溃

Electron应用程序在调用autoUpdater.CheckForUpdate时崩溃,electron,Electron,电子:6.0.9 电子更新程序:4.1.2 当我调用自动更新程序时,Electron应用程序崩溃。CheckForUpdate 没有互联网连接 应用程序崩溃,甚至被包围在try-catch块中 try { autoUpdater.checkForUpdates(); } catch(e) { logEverywhere('Error, Failed to check for updates!'); } 在electron fiddle上运

电子:6.0.9

电子更新程序:4.1.2

当我调用自动更新程序时,Electron应用程序崩溃。CheckForUpdate 没有互联网连接

应用程序崩溃,甚至被包围在try-catch块中

    try {
        autoUpdater.checkForUpdates();
    } catch(e) {
        logEverywhere('Error, Failed to check for updates!');
    }
在electron fiddle上运行此测试(使用autoUpdater.setFeedURL(“”)


autoUpdater.checkForUpdates()
是一个异步函数,返回承诺。您无法使用
try catch
捕获这些错误

以下是捕获错误的方式:

autoUpdater.checkForUpdates().catch(err => {
    console.error(`Something went wrong`, err);
});

不过,如果他使用async/await,他可以用try/catch处理它。所以你的答案只是部分正确。我不知道这里发生了什么。但你的回答对我有用。以后我会接受这个答案testing@FreddyDaniel如果您还不知道(回调的替代方案),我建议您理解并习惯它们,因为它们被广泛使用。函数也是一个很大的帮助,因为它们使承诺链变得更容易。:)@拉耶恩是对的。你应该了解承诺以及如何更好地运作。异步函数使用隐式承诺,所以在使用它们之前,您应该真正了解承诺是如何工作的。它们允许您清理代码,使其看起来像常规的同步语法。
autoUpdater.checkForUpdates().catch(err => {
    console.error(`Something went wrong`, err);
});