iOS 用@try @catch捕获异常

NSString *name = @"哈哈哈哈";

name = nil;

@try

{

NSDictionary *dict = @{@"name":name};

}@catch (NSException * e) {

NSLog(@"Exception: %@", e);

UIAlertView * alert =

[[UIAlertView alloc]

initWithTitle:@"错误"

message: [[NSString alloc] initWithFormat:@"%@",e]

delegate:self

cancelButtonTitle:nil

otherButtonTitles:@"OK", nil];

[alert show];

[alert release];

return;

}

你可能感兴趣的:(iOS 用@try @catch捕获异常)