iOS的@try、@catch()
NSArray *tabBarItems=self.tabBar.items;
NSArray * title = @[@"⾸页",@"分类",@"购物车",@"消息"];
@try {
[tabBarItems enumerateObjectsUsingBlock:^(UITabBarItem * indexItem, NSUInteger idx, BOOL *stop) { indexItem.title=[title objectAtIndex:idx];
indexItem.image=[UIImage imageNamed:[NSString stringWithFormat:@"menu_0%ld_normal",idx+1]];try catch的使用方法
NSLog(@"%ld",idx);
}];
}
@catch (NSException *exception) {
NSLog(@"%@",@"有异常");
}
@finally {
NSLog(@"%@",@"最后执⾏");
}
今天被同事问,所以学习了⼀下,为什么OC很少⽤@try @catch
在⽹上搜索到知乎上的答案,总结⼀下:
1、@try@catch解决异常的能⼒强吗?
2、@try@catch对资源消耗多吗?
3、Cocoa开发者习惯了?
结果是:
解决问题能⼒不强,并造成额外的开销,所以很少⽤?
问题留给⾃⼰,有时间在考证~
nice~
- 如果有什么疑问,可以在评论区⼀起讨论;
- 如果有什么不正确的地⽅,欢迎指导!
> 注:本⽂⾸发于iHTCboy's blog,如若转载,请注明来源。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。