xcode 我如何调试:libc++abi.dylib:以 NSException 类型的未捕获异常终止?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40426200/
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
How do I debug: libc++abi.dylib: terminating with uncaught exception of type NSException?
提问by Reilem
Sorry for asking this noob question, I know it has been asked thousands of times before, I know because I've had this problem thousands of times before. But this time google isn't helping.
很抱歉问这个菜鸟问题,我知道之前已经被问过数千次了,我知道因为我以前遇到过这个问题数千次。但这一次谷歌没有帮助。
The error / terminal print:
错误/终端打印:
libc++abi.dylib: terminating with uncaught exception of type NSException
I generally know what type of situations cause this because I have had this issue in the past and it was quite simple to fix, usually a misnamed function or a broken link between some UI element and my code, but right now I have no idea what could be causing it.
我通常知道什么类型的情况会导致这种情况,因为我过去遇到过这个问题,而且修复起来很简单,通常是函数命名错误或某些 UI 元素与我的代码之间的链接断开,但现在我不知道是什么可能导致它。
What I have already tried:
我已经尝试过的:
I've added tonnes of breakpoints on the starting ViewController and it goes through all the @IBOutlets without throwing any issues. I've added breakpoints in all the methods in the AppDelegate and it doesn't break anywhere there. The code crashes before it reaches any viewDidLoad() methods. I've cleaned my project, restarted XCode a thousand times and even broken and re-made every link between UI and code. Renamed and then reassigned every @IBAction.
我在起始 ViewController 上添加了大量断点,它通过所有 @IBOutlets 没有抛出任何问题。我已经在 AppDelegate 的所有方法中添加了断点,它不会在任何地方中断。代码在到达任何 viewDidLoad() 方法之前崩溃。我已经清理了我的项目,重新启动了 XCode 一千次,甚至破坏并重新制作了 UI 和代码之间的每个链接。重命名然后重新分配每个@IBAction。
At this point I don't even know what I haven't tried. Every stackoverflow posts is always about the same thing "check broken links etc" but that just isn't helping anymore. I can't remember what it was that I changed because I changed so many small things before I started getting this error. I tried putting everything back but that didn't seem to help.
在这一点上,我什至不知道我还没有尝试过什么。每个stackoverflow帖子总是关于相同的事情“检查断开的链接等”,但这不再有帮助。我不记得我改变了什么,因为在我开始出现这个错误之前我改变了很多小东西。我试着把所有东西都放回去,但这似乎没有帮助。
When the app crashes:
当应用程序崩溃时:
Right after "applicationDidBecomeActve()" is finished the debugger goes into a bunch of machine code, then the app crashes and I get this:
在“applicationDidBecomeActve()”完成后,调试器进入一堆机器代码,然后应用程序崩溃,我得到这个:
Proof of correct linking:
正确链接的证明:
[Images removed as they were unneccessary]
[图像因不必要而删除]
My main question(s):
我的主要问题:
If linking is not the issue here, what else could it be?
如果链接不是这里的问题,那还有什么问题?
About NSLogs/stack traces
关于 NSLogs/堆栈跟踪
I would love to provide some sort of NSLog or stack trace as I have seen people ask and give for on other questions but I have no idea how. I cannot find anything on the internet that isn't from the stone age on how to turn them on. And everything else is just how to use the debugger, but I am using the debugger and all I am getting are brief glimpses of my code in a see of machine instructions until it finally just crashes.
我很想提供某种 NSLog 或堆栈跟踪,因为我看到人们在其他问题上提出要求和给予,但我不知道如何。我在互联网上找不到关于如何打开它们的任何不是来自石器时代的东西。其他一切都只是如何使用调试器,但我正在使用调试器,我得到的只是在机器指令中对我的代码的简要介绍,直到它最终崩溃为止。
EDIT:
编辑:
Apparently I can only get logs when running on an emulator instead of physical device. Here are the logs I get when running on emulator:
显然,我只能在模拟器而不是物理设备上运行时获取日志。以下是我在模拟器上运行时得到的日志:
objc[40258]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x123242998) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x123067d38). One of the two will be used. Which one is undefined.
2016-11-04 16:26:47.463 KotConnect[40258:1345011] Unknown class ProgressViewContainer in Interface Builder file.
2016-11-04 16:26:47.500 KotConnect[40258:1345011] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIView 0x7fbfe3c0a030> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key loadingView.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001105ca34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011002b21e objc_exception_throw + 48
2 CoreFoundation 0x00000001105ca299 -[NSException raise] + 9
3 Foundation 0x000000010fb3b26f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x0000000110e0580d -[UIView(CALayerDelegate) setValue:forKey:] + 173
5 UIKit 0x000000011114f79e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000011056f590 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x000000011114e122 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x0000000110ee1c21 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
9 UIKit 0x0000000110ee2543 -[UIViewController loadView] + 177
10 UIKit 0x0000000110ee2878 -[UIViewController loadViewIfRequired] + 201
11 UIKit 0x0000000110f2307b -[UINavigationController _layoutViewController:] + 55
12 UIKit 0x0000000110f23963 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 471
13 UIKit 0x0000000110f23ada -[UINavigationController _startTransition:fromViewController:toViewController:] + 133
14 UIKit 0x0000000110f24ce5 -[UINavigationController _startDeferredTransitionIfNeeded:] + 874
15 UIKit 0x0000000110f25dc7 -[UINavigationController __viewWillLayoutSubviews] + 58
16 UIKit 0x000000011111cd6f -[UILayoutContainerView layoutSubviews] + 223
17 UIKit 0x0000000110e05f50 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
18 QuartzCore 0x0000000110ac3cc4 -[CALayer layoutSublayers] + 146
19 QuartzCore 0x0000000110ab7788 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
20 QuartzCore 0x0000000110ab7606 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x0000000110a45680 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
22 QuartzCore 0x0000000110a72767 _ZN2CA11Transaction6commitEv + 475
23 QuartzCore 0x0000000110a730d7 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113
24 CoreFoundation 0x000000011056ee17 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
25 CoreFoundation 0x000000011056ed87 __CFRunLoopDoObservers + 391
26 CoreFoundation 0x00000001105534b6 CFRunLoopRunSpecific + 454
27 UIKit 0x0000000110d3b7e6 -[UIApplication _run] + 434
28 UIKit 0x0000000110d41964 UIApplicationMain + 159
29 KotConnect 0x000000010d52cc8f main + 111
30 libdyld.dylib 0x00000001135c968d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
回答by dip
Swift
迅速
Just add
只需添加
NSSetUncaughtExceptionHandler { exception in
print(exception)
print(exception.callStackSymbols)
}
at the bottom of didFinishLaunchingWithOptionsmethod of AppDelegate. It will give you the better info about the exceptionoccurred. Happy coding !
在AppDelegate的didFinishLaunchingWithOptions方法的底部。它将为您提供有关发生异常的更好信息。快乐编码!
回答by Reilem
Once I was able to see my app log I could see my custom class was not being found. I'll leave the fix I found for this issue for any people who have this issue in the future:
一旦我能够看到我的应用程序日志,我就可以看到我的自定义类没有被找到。我会为将来遇到此问题的任何人留下我为此问题找到的修复程序:
Xcode 6 Strange Bug: Unknown class in Interface Builder file
回答by Kukiwon
This happened to me when I accidentaly removed one of my storyboards from my targets. Make sure to double check your Target Membership.
当我不小心从目标中删除了一个故事板时,这发生在我身上。请务必仔细检查您的目标会员资格。