OC : NSException (崩溃)

来源:互联网 发布:suse yum源配置 编辑:程序博客网 时间:2024/05/22 19:44
@interface NSException : NSObject <NSCopying, NSCoding> {    @private    NSString        *name;    NSString        *reason;    NSDictionary    *userInfo;    id          reserved;}

@try @catchObjective-C 异常捕捉机制

  • @try存放可能出现异常的代码 - 发现异常
  • @catch异常处理逻辑 - 捕捉异常 && 处理异常
  • @finally回收资源 – 执行收尾

【使用方法】

     NSException *exc = [[NSException alloc]initWithName:@"had error" reason:@"speak english" userInfo:nil];    @try {        if (![@"english" isEqualToString:@"chinese"]) {              @throw exc;        }    }    @catch ( NSException *exception ) {        NSLog(@"exception.name = %@" , exception.name);        NSLog(@"exception.reason = %@" , exception.reason);    }    @finally {        NSLog(@"@finally");    }
    NSString *message = @"this is a error exception .";    [NSException raise:@"WKErrorException" format:message,nil];

推荐阅读:

http://www.jianshu.com/p/05aad21e319e

http://blog.csdn.net/a1484/article/details/27173561

http://www.jianshu.com/p/20e21498d2a9

原创粉丝点击