1

Is there a reason why the following wouldn't work?

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

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");
}
4

1 回答 1

10

是的,有一个非常简单的原因。即,CFGetTypeID(NULL)不抛出异常。它正在崩溃。你无法捕捉到这样的崩溃。

于 2012-03-16T23:03:02.337 回答