简体   繁体   中英

Debugging uncaught exception in Xcode

I'm trying to get better at using Xcode. I have the AllExceptions break point turned on. 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. I see some CFRunLoop stuff, but I don't see any "normal" method names like UITableView delegate/datasource methods or my own methods. 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. Thanks!

In 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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