鸟语天空
使用@try处理异常
post by:追风剑情 2019-2-22 16:39

示例

#import <Foundation/Foundation.h>
#import "Fraction.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        //主动抛出异常
        //@throw [NSException exceptionWithName:@"context show" reason:@"crush's reason" userInfo:nil];
        
        Fraction *f = [[Fraction alloc] init];

        @try {
            [f noSuchMethod];
        }
        @catch (NSException *exception) {
            NSLog(@"Caught %@%@", [exception name], [exception reason]);
        }
        @finally {
            NSLog(@"finally...");
        }
        
        NSLog(@"Execution continues!");
    }
    return 0;
}

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容