NSException 异常捕获和处理
依赖基础库Foundation, 直接看代码
#import <Foundation/Foundation.h>
int main() {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *array = [[NSMutableArray alloc]init];
@try {
NSString *string = [array objectAtIndex:10];
} @catch (NSException *exception) {
NSLog(@"%@ ",exception.name);
NSLog(@"Reason: %@ ",exception.reason);
}
@finally {
NSLog(@"@@finaly Always Executes");
}
[pool drain];
return 0;
}
Objective-C也是有try catch fianlly 三段捕获异常的语句段。
跟Java,C#没什么太大区别,用起来也很顺手。
捕获异常,打印日志,轻松搞定
分类: 默认 标签: 发布于: 2021-12-02 11:33:58, 更新于: 2021-12-02 11:33:58