简体   繁体   English

在 Xcode 中调试未捕获的异常

[英]Debugging uncaught exception in Xcode

I'm trying to get better at using Xcode.我正在努力更好地使用 Xcode。 I have the AllExceptions break point turned on.我打开了 AllExceptions 断点。 When my app crashes, I see this:当我的应用程序崩溃时,我看到:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(0xbb8052 0x209cd0a 0xba4db8 0x2255f2 0xc2439 0x12a5e0f 0x12a6589 0x146bfb1 0x147617c 0x12938e1 0x1290602 0x129b211 0x129b23f 0xc16a6 0x138a4c 0x138852 0x14d0e39 0x14d0143 0x14d13cf 0x14d3a31 0x14d398c 0x14cc3e7 0x1234812 0x1234ba2 0x121b384 0x120eaa9 0x28d3fa9 0xb8c1c5 0xaf1022 0xaef90a 0xaeedb4 0xaeeccb 0x28d2879 0x28d293e 0x120ca9b 0x265c 0x25c5)
terminate called throwing an exception(lldb) 

On the LHS, when I look at the different threads, I don't see anything that really makes sense.在 LHS 上,当我查看不同的线程时,我看不到任何真正有意义的内容。 I see some CFRunLoop stuff, but I don't see any "normal" method names like UITableView delegate/datasource methods or my own methods.我看到了一些 CFRunLoop 的东西,但我没有看到任何“正常”的方法名称,如 UITableView 委托/数据源方法或我自己的方法。 I was wondering if there was a more informative stack trace available instead of the hex stuff when my app crashes.我想知道当我的应用程序崩溃时是否有更多信息可用的堆栈跟踪而不是十六进制的东西。 I know I can set breakpoints at each place I'm accessing the array I think I have a problem with since I'm basically just trying to have an accordion-like tableview with our specific datasource, but I was wondering if there was a faster way by looking at something useful in Xcode.我知道我可以在我访问数组的每个地方设置断点我想我有问题,因为我基本上只是想用我们的特定数据源创建一个类似手风琴的 tableview,但我想知道是否有更快的通过查看 Xcode 中有用的东西。 Thanks!谢谢!

In Xcode,在Xcode中,

  1. go to Breakpoint navigator on the left pane.转到左侧窗格中的断点导航器。
  2. Click '+' at the bottom.点击底部的“+”。
  3. Choose 'Add exception Breakpoint...'选择“添加异常断点...”
  4. Let the default selections there and click 'Done'.让默认选择在那里,然后单击“完成”。

Rerun the app and see if execution stops at the line which causing this exception.重新运行应用程序并查看执行是否在导致此异常的行处停止。

The easiest way to handle the exceptions in XCode during development is to add the exception break points.在开发过程中处理 XCode 中的异常最简单的方法是添加异常断点。

You can do that as following.您可以按以下方式执行此操作。

  1. From left menu select Exceptions navigator从左侧菜单中选择例外导航器

在此处输入图片说明

  1. Add the exception break point from bottom left button.从左下角按钮添加异常断点。

在此处输入图片说明

  1. Add break point for all the exceptions为所有异常添加断点

在此处输入图片说明

  1. Run the app.运行应用程序。

In most of the cases XCode will stop the execution on exception and point at the line that caused the exception.在大多数情况下,XCode 将停止执行异常并指向导致异常的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM