开发者

Objective C - Caught exception causes crash

开发者 https://www.devze.com 2023-03-28 05:32 出处:网络
I\'m doing some Objective C tests. I\'m raising a custom exception with this code: - (double)foo:(int)x{

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

0

精彩评论

暂无评论...
验证码 换一张
取 消