【问题标题】:Can not catch exception, while vscode dart-code DOES catch the exception无法捕获异常,而 vscode dart-code 确实捕获了异常
【发布时间】:2021-05-15 12:34:25
【问题描述】:

我的 Flutter 应用中有一行代码导致 VSCode 因异常而中断。

为了让这种行为发生,我在 vscode dart-code 扩展中启用了“中断未捕获的异常”。

观察下面的代码。带有 await 的行使 vscode 在“未捕获的异常”上中断,但该异常肯定被我捕获了。

vscode 如何在这一行的未捕获异常上中断,而该异常实际上随后被 runZoned 或 try/catch 捕获?

runZoned(
  () async {
    try {
      if (_readCharSubscription != null)
        await _readCharSubscription.cancel();
    }
    catch(e) {
      print("caught");
    }
  },
  onError: (e) {
    print("caught");
  }
);

【问题讨论】:

标签: flutter dart visual-studio-code


【解决方案1】:

我的猜测是该异常并非真的没有被捕获。在某些情况下,VM 会在将要处理的异常上暂停,即使设置设置为仅在未捕获的异常上中断。

相关的 SDK 问题在这里:

https://github.com/dart-lang/sdk/issues/37953

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 2021-10-09
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    相关资源
    最近更新 更多