我正在做一些Objective C测试。我用这段代码提出了一个自定义异常:
- (double)foo:(int)x{
if (x == 0){
[NSException raise:@"InvalidX" format:@"X can't be 0"];
}
return 1/x;
}
并使用此代码捕获它:
@try {
double y = [self foo:0];
} @catch (NSException *e) {
return;
}
如果我在XCode中运行应用程序,但是当我运行.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:
它看起来并不“未被捕获”!我无法解释这个