简体   繁体   English

iOS 64bit @try {...} @catch {...}无效

[英]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). 最近我为我的iOS项目(arm64)添加了64位支持,从那以后,我开始在@try...@catch中找到我的代码段的未捕获异常@try...@catch (我正在使用Crashlytics进行崩溃报告)。 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): 我设法在我的应用程序的任何地方使用以下代码行重现问题(我在其中一个视图控制器的init中编写):

@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. 异常被UncaughtExceptionHandler而不是@catch子句UncaughtExceptionHandler 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. 我尝试删除我拥有的自定义异常处理程序并禁用Crashlytics,但仍然没有成功。

As soon as I remove arm64 from ARCHS and VALID_ARCHS the code works and the exception is caught as expected. 只要我从ARCHSVALID_ARCHS删除arm64 ,代码就会正常工作,异常会按预期捕获。

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. 小更新 - 我们的XCTests也开始不捕获异常,直到现在这种行为只发生在物理64位手机上。

After a long session of git-bisecting the culprit was the following linker flag 经过长时间的git-bisecting之后,罪魁祸首是以下链接器标志

-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). 我使用了BlocksKit v2.2.0仍然有那个标志,即使它停止使用libffi(最新版本的BlocksKit删除了那个不需要的标志)。 As soon as I removed that linker flag 64bit @try...@catch blocks started to work again. 一旦我删除了那个链接标志64bit @try...@catch blocks再次开始工作。

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 表示不快

On iOS and Objective-C Exceptions are only to be used for un-recoverable programming errors, not for program execution control. 在iOS和Objective-C上,异常仅用于不可恢复的编程错误,而不用于程序执行控制。

In particular they do not handle catches accross stack frames inthe APIs. 特别是它们不处理API中堆栈帧的捕获。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM