本文介绍了Objective-c尝试/捕获未捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否存在以下原因不起作用的原因?
Is there a reason why the following wouldn't work?
@try {
CFGetTypeID( NULL );
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
@finally {
NSLog(@"finally");
}
类似于 try/catch问题,但似乎上面的块每次都会崩溃.我知道我的调试器设置正确,因为我在上面的另一个问题中设置了try/catch:
Similar to the try/catch question, only it seems the above block crashes everytime. I know my debugger is setup correctly, as I setup a try/catch above from the other question:
// Test working try catch
NSString* test = [NSString stringWithString:@"ss"];
@try {
[test characterAtIndex:6];
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
@finally {
NSLog(@"finally");
}
// Now test NULL entry
@try {
CFGetTypeID( NULL );
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
@finally {
NSLog(@"finally");
}
推荐答案
是的,原因很简单.即,CFGetTypeID(NULL)
不会引发异常.崩溃了您无法捕捉到这样的崩溃.
Yes, there is a very simple reason. Namely, CFGetTypeID(NULL)
isn't throwing an exception. It's crashing. You can't catch crashes like this.
这篇关于Objective-c尝试/捕获未捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!