0

The following code in main does a great job of catching UncaughtExceptions - at least until iOS 8, that is.

int main(int argc, char * argv[])
{
    @try {
        @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));
        }
    }
    @catch (NSException *exception) {
        [[MyExceptionHandler sharedInstance] handleException:exception];
    }
}

Running the same code on an iOS 7 device, any uncaught exceptions are handled by the catch block in main. However in iOS 8 it is not caught at all.

If I place this code:

void onUncaughtException(NSException* exception)
{
    [[MyExceptionHandler sharedInstance] handleException:exception];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ....
  NSSetUncaughtExceptionHandler(&onUncaughtException);
}

in my AppDelegate, I can catch all exceptions as expected. I am just wondering what's the reason for the @catch-in-main-approach to have stopped working in iOS 8 (or is it perhaps related to 64-bit support)?

Regards,

Christian

Caleb
  • 124,013
  • 19
  • 183
  • 272
ckibsen
  • 943
  • 1
  • 7
  • 9

1 Answers1

0

According to this post:

iOS 64bit @try {... } @catch {...} not working

it seems to be 64 bit related. See the comment from @bbum

Community
  • 1
  • 1
pbodsk
  • 6,787
  • 3
  • 21
  • 51