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

ぐ巨炮叔叔 提交于 2019-12-07 02:29:01

问题


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)


回答1:


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

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

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




回答2:


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.



来源:https://stackoverflow.com/questions/46408727/how-do-i-know-which-line-of-code-has-caused-my-ios-app-to-crash-in-xcode-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!