关键字:
@try @catch @finally @throw
注意:当前catch到的异常可以重新throw出去,但当前的异常处理会先执行完毕再执行其他的。
int main(int argc, char* argv[]) { @try{ @try { NSException *e = [NSException exceptionWithName: @"myException" reason: @"fuck reason" userInfo: [[NSDictionary alloc] init]]; @throw e; printf("try "); } @catch (NSException *e){ printf("inner catch "); @throw e; } @finally{ printf("finally "); } } @catch (NSException* e){ printf("outer catch "); } return 0; }
上面代码中catch到的异常throw了出去,但还是会先执行finally,再执行outer catch: