1

我正在做一些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:

它看起来并不“未捕获”!我无法解释这个

4

0 回答 0