Objective-C 异常处理
1 #import <UIKit/UIKit.h> 2 #import "AppDelegate.h" 3 4 int main(int argc, char * argv[]) { 5 6 @try { 7 // 抛出一个自定义异常 8 @throw [NSException exceptionWithName:@"My Error" reason:nil userInfo:nil]; 9 } 10 @catch (NSException *exception) { 11 // 处理异常 12 NSLog(@"%@",exception); 13 } 14 @finally { 15 // 运行 16 NSLog(@"run"); 17 } 18 19 @autoreleasepool { 20 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 21 } 22 }