Objective C - Caught exception causes crash
I'm doing some Objective C tests. I'm raising a custom exception with this code:
- (double)foo:(int)x{
if (x == 0){
[NSException raise:@"InvalidX" format:@"X can't be 0"];
}
return 1/x;
}
and catching it with this code:
@try {
double y = [self foo:0];
} @catch (NSException *e) {
return;
}
开发者_JAVA百科
It works good if i run the application in XCode but it crashes when i run the .app:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
objc[1769]: garbage collection is OFF
*** Terminating app due to uncaught exception 'InvalidX', reason: 'X can't be 0'
*** First throw call stack:
It doesn't look "uncaught"! I can't explain this
精彩评论