异常处理

@interface Car : NSObject
@end

@interface Seller : NSObject
@property NSArray<Car *> *cars;
-(void) sell;
@end

@implementation Seller : NSObject
-(void) sell {
    if (self.cars.count == 0) {
        NSException *e = [NSException
            exceptionWithName:@"NoCars"
            reason:@"No cars for sale"
            userInfo:nil];
        @throw e;
    }
}
@end

Seller *seller = [[Seller allocinit];
@try {
    [seller sell];
}
@catch (NSException *e) {
    NSLog(@"%@", e.reason);
    //reason is "No cars for sale"
}