void throwIfTrue(bool param) {
//@try 没有 "else":块的末尾部分只有在没有抛出异常时才会运行
@try {
if (param) {
@throw [NSException
exceptionWithName:@"Test"
reason:@"test"
userInfo:nil];
}
NSLog(@"else");
}
@catch (NSException *e) {
NSLog(@"except");
}
}
throwIfTrue(true);
//printed: 'except'
throwIfTrue(false);
//只输出 'else'