7-5 异常捕捉(try...catch)

7-5 异常捕捉(try...catch)

#import 
//  异常处理
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSMutableArray  *array = [NSMutableArray array];
        [array addObject:@"aa"];
        [array addObject:@"aa"];
        [array addObject:@"aa"];
        [array addObject:@"aa"];
        @try
        {
            [array objectAtIndex:3];
            NSLog(@"成功执行");
        }
        @catch(NSException *exception)
        {
            NSLog(@"原因:%@ %@", exception.name, exception.reason);
        }
        
    }
    return 0;
}

你可能感兴趣的:(7-5 异常捕捉(try...catch))