Objective-c Try/Catch not catchching
问题描述:
是否有下列原因不起作用?Objective-c Try/Catch not catchching
@try {
CFGetTypeID(NULL);
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
@finally {
NSLog(@"finally");
}
与try/catch question类似,只是看起来上面的块每次都崩溃。我知道我的调试器设置正确,因为我建立一个try /上述来自其它问题捉:
// 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)
没有引发异常。它正在崩溃。你不能碰到这样的崩溃。