int afunc() {
throw '123'; //抛异常
}
void main() {
int? a;
try {
//但是返回值的类型,需要匹配的,不然语法报错
a = afunc(); //抛异常,等于这个赋值没执行,a原来是什么还是什么
} catch (e) {
print(e);
}
print(a);
List l = ['1'];
String? r = '123';
try {
r = l.elementAt(9); //抛异常,等于这个赋值没执行,a原来是什么还是什么
} catch (e) {
print(e);
}
print(r);
}
执行结果:
123
null
RangeError (index): Index out of range: index should be less than 1: 9
123
网友评论