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