Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging uncaught exception in Xcode

Tags:

xcode

ios

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!

like image 616
Crystal Avatar asked Feb 21 '13 22:02

Crystal


People also ask

How do I debug an exception in Xcode?

Step 1 − To add an exception breakpoint, first move to breakpoint navigator in xcode. Step 2 − Click on the + option at the left bottom of the navigator and select Exception breakpoint. Once you select exception breakpoint, it will be added to our code.

How do I enable debug mode in Xcode?

When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.

How do you add a breakpoint in Xcode?

Navigate to a line in your code where you want execution to pause, then click the gutter or line number in the source editor to set a breakpoint. Xcode displays a breakpoint icon to indicate the location. Drag a breakpoint up or down to move it to another location; drag it away from the gutter to remove it.


2 Answers

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.

like image 160
Saran Avatar answered Oct 19 '22 17:10

Saran


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

enter image description here

  1. Add the exception break point from bottom left button.

enter image description here

  1. Add break point for all the exceptions

enter image description here

  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.

like image 21
Mohammad Sadiq Avatar answered Oct 19 '22 18:10

Mohammad Sadiq