Objective-c Try/Catch没有捕获

Cor*_*art 1 objective-c try-catch-finally nsexception ios

是否有以下原因无效?

@try {
    CFGetTypeID( NULL );
}
@catch (NSException * e) {
    NSLog(@"Exception: %@", e);
}
@finally {
    NSLog(@"finally");
}
Run Code Online (Sandbox Code Playgroud)

try/catch问题类似,只是看起来上面的块每次都崩溃了.我知道我的调试器设置正确,因为我从另一个问题设置了一个try/catch:

// 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");
}
Run Code Online (Sandbox Code Playgroud)

Lil*_*ard 10

是的,有一个非常简单的原因.也就是说,CFGetTypeID(NULL)不是抛出异常.它崩溃了.你不能抓住像这样的崩溃.