Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a very peculiar issue.

Recently I added 64bit support to my iOS project (arm64), ever since doing that I started receiving uncaught exceptions for segments of my code inside @try...@catch (I'm using Crashlytics for crash reporting). I managed to reproduce the problem with the following lines of code anywhere in my app (I wrote them inside init of one of my view controllers):

@try {
    NSMutableDictionary *m = [[NSMutableDictionary alloc] init];
    NSString *s;
    m[s] = @"poop";
} @catch (NSException *e) {
    NSLog(@"POOP");
}

The exception gets caught by the UncaughtExceptionHandler instead of the @catch clause. I'm confused as to what can cause this. The output in the console:

2015-02-22 19:19:53.525 [391:30650] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'
*** First throw call stack:
(0x18823a59c 0x1989400e4 0x1881251f8 0x10011e2f4 0x10011e068 0x10010e480 0x10010db78 0x10010d944 0x1000a8050 0x100075d88 0x100075160 0x100142044 0x100141f6c 0x18c9ecaa0 0x18caa1fb4 0x18caa1eb0 0x18caa134c 0x18caa0ff8 0x18caa0d18 0x18caa0c98 0x18c9e9648 0x18c341994 0x18c33c564 0x18c33c408 0x18c33bc08 0x18c33b98c 0x18cc76dbc 0x18cc77c68 0x18cc75dec 0x1904b162c 0x1881f2a28 0x1881f1b30 0x1881efd30 0x18811d0a4 0x18ca573c8 0x18ca523c0 0x1000747d8 0x198faea08)
libc++abi.dylib: terminating with uncaught exception of type NSException

I tried removing the custom exception handler that I have and disabling Crashlytics, still no success.

As soon as I remove arm64 from ARCHS and VALID_ARCHS the code works and the exception is caught as expected.

Any information will be appreciated!


Small update - our XCTests also started not to catch exceptions, up until now the behaviour only happened on physical 64bit phones.

like image 718
Nimrod Gutman Avatar asked Sep 29 '22 16:09

Nimrod Gutman


1 Answers

After a long session of git-bisecting the culprit was the following linker flag

-no_compact_unwind

I Used BlocksKit v2.2.0 which still had that flag even though it stopped using libffi (latest version of BlocksKit removed that unneeded flag). As soon as I removed that linker flag 64bit @try...@catch blocks started to work again.

I still don't have complete understanding of why this behaviour happens but I'm going to dig a bit more and update this thread if I find anything interesting.

phew

like image 199
Nimrod Gutman Avatar answered Oct 25 '22 11:10

Nimrod Gutman