iOS 64 位 @try {... } @catch {...} 不起作用 [英] iOS 64bit @try {... } @catch {...} not working

查看:30
本文介绍了iOS 64 位 @try {... } @catch {...} 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很奇怪的问题.

I have a very peculiar issue.

最近我为我的 iOS 项目 (arm64) 添加了 64 位支持,从那时起,我开始收到 @try...@catch 中代码段的未捕获异常(我正在使用用于崩溃报告的 Crashlytics).我设法在我的应用程序中的任何位置使用以下代码行重现了该问题(我在我的一个视图控制器的 init 中编写了它们):

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");
}

异常被 UncaughtExceptionHandler 而不是 @catch 子句捕获.我很困惑是什么导致了这种情况.控制台输出:

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

我尝试删除我拥有的自定义异常处理程序并禁用 Crashlytics,但仍然没有成功.

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

一旦我从 ARCHSVALID_ARCHS 中删除了 arm64,代码就会正常工作,并且异常被按预期捕获.

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

任何信息将不胜感激!

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

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

推荐答案

经过长时间的 git 一分为二,罪魁祸首是以下链接器标志

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

-no_compact_unwind

我使用了 BlocksKit v2.2.0,即使它停止使用 libffi(最新版本的 BlocksKit 删除了不需要的标志),它仍然具有该标志.一旦我删除了那个链接器标志 64 位 @try...@catch 块又开始工作了.

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.

这篇关于iOS 64 位 @try {... } @catch {...} 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆