【发布时间】:2017-07-15 09:33:53
【问题描述】:
在目标 c 中,我们使用 try catch 来停止崩溃,例如
- (void)viewDidLoad {
[super viewDidLoad];
tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
@try {
NSLog(@"%@",tableData[1000]);
} @catch (NSException *exception) {
NSLog(@"%@",exception);
}
}
但是当我使用 swift 3 时,警告显示和应用程序崩溃
谁能解释一下,我该如何阻止它。我从谷歌阅读了一些主题,但无法理解。谁能帮帮我。
【问题讨论】:
-
Swift 的
try - catch表达式确实不 捕捉异常,它确实明确捕捉thrown 错误。改进您的代码以避免引发异常。
标签: swift