Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know which line of code has caused my iOS app to crash in Xcode 9

I am building an app in Xcode 9 (Swift 4) and it crashes before it even loads completely. I get an error: Thread 1: Signal SIGABRT and libc++abi.dylib: terminating with uncaught exception of type NSException. How do I know which line of code is causing the error using breakpoints and debugging? Any help would be appreciated. Thanks! (Here's a screenshot as well)enter image description here

like image 242
ojassethi Avatar asked Sep 25 '17 15:09

ojassethi


2 Answers

What you need here is an exception breakpoint. An exception breakpoint is a special kind of breakpoint that breaks whenever an exception occurs, instead of on a specific line in a specific file every time. The line where the breakpoint breaks is the line that throws the exception. To set an exception breakpoint, you'll need to open the breakpoint navigator and press the + button in the bottom left

Xcode breakpoint navigator

A little menu will pop up, and from that, you select Exception Breakpoint…

Exception Breakpoint option

A 3rd menu might pop up afterwards, but you can just click anywhere outside of it to dismiss it. After that, when you build and run your app again, it will break whenever an exception is thrown on the line that it is thrown

like image 170
Michael Hulet Avatar answered Nov 14 '22 21:11

Michael Hulet


You gotta scroll up to see the error. If you scroll up above all the "terminating with uncaught exception of type NSException" stuff you will see something like "Terminating app due to blah blah blah" and then in the next line right below it will say "reason: blah blah blah". That should tell you why the app crashed.

like image 42
YungGoat Avatar answered Nov 14 '22 22:11

YungGoat