是否有适当的方法来捕获 block 代码中的异常?
我得到了以下代码:
void(^callback(int) = ^(int respond){
[self DoSomethingWithRespond:respond]; //this throws an exception
};
-(void)DoSomethingWithRespond:(int)respond{
if(respond == 400){
NSException *exception = [NSException
exceptionWithName:@"Failed"
reason:logMessage
userInfo:nil];
@throw exception
}
}
回调方法从另一个线程调用。如果响应等于 400,DoSomethingWithRespond
方法将抛出异常。
最佳答案
@try {
<#statements#>
}
@catch (NSException *exception) {
<#handler#>
}
@finally {
<#statements#>
}
关于objective-c - 如何在 BlockCode 中捕获异常( Objective-C ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10877848/