Xcode 在带有“所有异常”断点的 iOS 8 中的 Main() 中抛出异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26127004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode throws an exception in Main() in iOS 8 with 'all exceptions' breakpoint
提问by invalidArgument
I am using Xcode 6 (GM, I didn't download betas), and I am developing apps for iOS 7+. For all my projects, I just opened the same projects I used to work on in Xcode 5.
我正在使用 Xcode 6(GM,我没有下载测试版),我正在为 iOS 7+ 开发应用程序。对于我的所有项目,我只是打开了我曾经在 Xcode 5 中工作的相同项目。
In the Breakpoint navigator, I have the All Exceptions
breakpoint on. It is set to Break: On Throw
. Now, each time I run my app (whether on a device or in simulator), it stops execution on the line return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
in the main()
function.
在断点导航器中,我打开了All Exceptions
断点。它被设置为Break: On Throw
。现在,每次我运行我的应用程序时(无论是在设备上还是在模拟器中),它都会return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
在main()
函数的行上停止执行。
If I press Play to continue program execution twice, the program runs fine. So this doesn't prevent me from working, but it is annoying to have to manually play the execution each time and reset my editors.
如果我按 Play 两次继续程序执行,程序运行良好。所以这并不妨碍我工作,但是每次必须手动播放执行并重置我的编辑器很烦人。
I like the behaviors I have set up in Xcode (taking the current editor to where the execution has paused), and having that All Exceptions
breakpoint is important IMO. (So I don't want to change those)
我喜欢我在 Xcode 中设置的行为(将当前编辑器带到执行暂停的位置),并且拥有该All Exceptions
断点很重要 IMO。(所以我不想改变那些)
By running the same code, with the same environnements, for an iOS 7 target (again, device or simulator), the exception is not thrown.
通过为 iOS 7 目标(同样是设备或模拟器)在相同的环境中运行相同的代码,不会抛出异常。
Any clue what could cause this strange behavior?
任何可能导致这种奇怪行为的线索?
回答by Johnnywho
As stated in the comments, you should turn off catching the C++ exceptions by editing your All Exceptionsbreakpoint.
如评论中所述,您应该通过编辑所有异常断点来关闭捕获 C++ 异常。
In order to do that, right click on your breakpoint and change Exceptionfrom Allto Objective-C:
为此,请右键单击您的断点并将Exception从All更改为Objective-C:
Exceptions in C++ code are part of normal app functionality. However, exception breakpoint is not catching unhandled but every raised exceptions, even when they're handled correctly later on, hence the stop in execution.
C++ 代码中的异常是正常应用程序功能的一部分。但是,异常断点不是捕获未处理的而是每个引发的异常,即使它们稍后被正确处理,因此停止执行。
回答by Andris Zalitis
TLDR; In my case the cause of problem was missing fonts.
TLDR;就我而言,问题的原因是缺少字体。
I also had this problem. While @Johnnywho is correct that leaving Exception Breakpoint for Objective-C only, stops the unwanted behaviour, it still does not explain what is the real cause, why does it run without exception on iOS7 and why does this happen only on some projects.
我也有这个问题。虽然@Johnnywho 是正确的,只为 Objective-C 留下异常断点,停止不需要的行为,但它仍然没有解释真正的原因是什么,为什么它在 iOS7 上毫无例外地运行,以及为什么这只发生在某些项目中。
That's why I went on and dissected one of my projects in which I had this problem, until the point where I was able I found the cause. I suppose that there could be more than one cause for this behaviour, but in my case that was missing custom fonts.
这就是为什么我继续剖析我遇到这个问题的一个项目,直到我能够找到原因为止。我想这种行为可能有不止一个原因,但就我而言,缺少自定义字体。
Quick way to test it:
快速测试方法:
Start a new single view project
Enable breakpoint on all exceptions, including C++ (Breakpoints / + / Add Exception Breakpoint)
Drag into the project some custom font (allow copying and check the target to add it to)
Add a label to the view in the main view controller
Choose the custom font for your label (on Xcode 6+ it should show in the font picker as soon as you drag it into the project).
Run the app and confirm that you see the label in your custom font (it seems that we don't need to add the font file name in Info.plist for the key "Fonts provided by application" anymore, if the custom font has been used in a storyboard of xib of the app).
Now remove the custom font from your project (either by unticking target relationship or by removing it in target settings / Build Phases / Copy Bundle Resources)
Delete the app from your device or sim (to delete the font file from the app bundle)
Product / Clean
Run the app again (now the label still has the reference to the custom font but the app does not have the file for it). You should notice the mysterious exception if you run on iOS8.
Run the app on device with iOS7 or sim with iOS7 (you'll need to change the iOS Deployment Target to iOS7 for that). Although the label won't show the custom font, there won't be an exception.
Add the font file back to the target and the breakpoint does not stop on run anymore.
开始一个新的单一视图项目
在所有异常上启用断点,包括 C++ (Breakpoints / + / Add Exception Breakpoint)
将一些自定义字体拖入项目(允许复制并检查目标以将其添加到)
在主视图控制器中为视图添加标签
为您的标签选择自定义字体(在 Xcode 6+ 上,只要您将其拖入项目,它就会显示在字体选择器中)。
运行应用程序并确认您在自定义字体中看到了标签(如果自定义字体已在应用程序的 xib 的故事板中使用)。
现在从您的项目中删除自定义字体(通过取消目标关系或通过在目标设置/构建阶段/复制捆绑资源中删除它)
从您的设备或 SIM 卡中删除应用程序(从应用程序包中删除字体文件)
产品 / 清洁
再次运行应用程序(现在标签仍然具有对自定义字体的引用,但应用程序没有它的文件)。如果你在 iOS8 上运行,你应该注意到这个神秘的异常。
在带有 iOS7 的设备上运行应用程序或在带有 iOS7 的 sim 上运行应用程序(为此,您需要将 iOS 部署目标更改为 iOS7)。虽然标签不会显示自定义字体,但也不会有例外。
将字体文件添加回目标,断点不再在运行时停止。
So my conclusion is that on iOS8 the missing fonts cause C++ exception while on iOS7 they don't, hence the breakpoint trigger.
所以我的结论是,在 iOS8 上,缺少的字体会导致 C++ 异常,而在 iOS7 上则不会,因此会触发断点。
Similar exception (and breakpoint trigger) can also be caused by incorrectly written font file name in Info.plist file under the key "Fonts provided by application".
类似的异常(和断点触发)也可能是由于在 Info.plist 文件中“应用程序提供的字体”项下的字体文件名写错了。
回答by Paulius Vindzigelskis
Just summarized previous answers which helped me to fix it.
只是总结了以前的答案,这帮助我解决了这个问题。
Problem: When you add custom font and then apparently delete (replace) it, somewhere in project is still his reference and the breakpoint stops several times at main C++ lib breakpoint stops in iOS 8.
问题:当您添加自定义字体然后显然删除(替换)它时,项目中的某处仍然是他的引用,并且断点在 iOS 8 中的主 C++ lib 断点停止处停止了几次。
Solutions
解决方案
1) Find in project and delete (replace) all references to those fonts. Might in some nibs, submodules, etc…
1)在项目中查找并删除(替换)对这些字体的所有引用。可能在一些笔尖、子模块等中......
2) If you can't fix everywhere (e. x. read-only libs use them) or problem still exists after solution 1 , add those old fonts back to project
2)如果你不能到处修复(例如只读库使用它们)或解决方案1后问题仍然存在,请将那些旧字体添加回项目
3) Ignore it - It is C++ lib so change breakpoint exception from “All" to "Objective-C" only
3) 忽略它 - 它是 C++ lib,所以将断点异常从“All”更改为“Objective-C”
回答by Ted
回答by Sunil Kumar
I had a same issue, the issue was i have added some interface files from other project which has different font in it. Just find them and remove.
我遇到了同样的问题,问题是我从其他项目中添加了一些界面文件,这些文件中有不同的字体。只需找到它们并删除即可。