flutter - 使用`flutter drive`时如何捕获异常?
问题描述
flutter drive
即使堆栈中存在运行时异常,使用我的测试仍然可以通过。
例如,将此代码添加到 build() 中,不会被检测到:
int? i;
i!.round();
有谁知道我怎么能在这个错误上失败?
解决方案
try{}
catch(e){print('error: $e')}
如果您知道异常,请以这种方式添加:-
try
on
catch
推荐阅读
- ios - iOS | 网址会话 | 下载任务| 当用户在应用程序之间切换并来时,didWriteData 没有调用
- python-3.x - 如何让shell脚本一直运行
- django - 如何在 django 中使用 redis 数据库?
- java - 如何在 Java 中将 double 类型转换为 T 泛型类型?
- java - 换屏javaFX
- c - 为什么在 C 中首先执行带有时钟()的 while 循环?
- azure-devops - Azure 管道的 Azure DevOps 组织范围变量
- redis - 如何在 Redis 中获取所有 Item 的 TTL?
- mongodb - Percona for MongoDB with Encryption at Rest - 如何导入未加密的 JSON 备份?
- xml - 将 XML 转换为 Perl 哈希