我有以下代码:
void main(List<String> arguments) {
print('Enter your age: ');
try {
int? age = int.tryParse(stdin.readLineSync()!);
print('Age is $age');
assert(age != null, 'Age cannot be null');
print('You are $age years old');
} catch (e) {
print('You gave us a bad age');
}
}
当我运行程序,输入像“nnnnn”这样的字符串(无法解析为整数)作为年龄时,我以为断言会抛出错误,但输出却是“你的年龄为 null 岁”。我是 Dart 新手,这让我抓狂,我是不是哪里操作错了?谢谢