iphone object_c 也支持异常捕获,用过没有呀。 在处理UITableView, MKMapView等,你可以加一些异常捕获,因为显示数据常常出错。
下面是示例代码:
@try
{
Statements
}
@catch (NSException *ex) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:[ex name]
message:[ex reason]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
}
注意,你的方法中要支持UIAlertViewDelegate协议。