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");
}
Community
  • 1
  • 1
Corey Hart
  • 10,316
  • 9
  • 41
  • 47

1 Answers1

10

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.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347