Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug: libc++abi.dylib: terminating with uncaught exception of type NSException?

Tags:

xcode

ios

swift

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.

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.

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.

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:

enter image description here

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

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.

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) 
like image 863
Reilem Avatar asked Nov 04 '16 15:11

Reilem


1 Answers

Swift

Just add

NSSetUncaughtExceptionHandler { exception in
   print(exception)
   print(exception.callStackSymbols)
}

at the bottom of didFinishLaunchingWithOptions method of AppDelegate. It will give you the better info about the exception occurred. Happy coding !

like image 71
dip Avatar answered Sep 18 '22 20:09

dip