Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out what exception was thrown in the Xcode debugger (for iPhone)?

I'm learning iPhone programming from Erica Sadun's The iPhone Developer's Cookbook. When I run the app I created by following the steps in the Temperature Conversion Example starting on page 81 in the simulator, it terminates due to an uncaught exception. (See http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=en for the question I posted to the iPhoneSDK Google Group.)

The exception is thrown after calling UIApplicationMain() from my main(). If I look through the stack trace in the debugger, all I see is (of course) assembly. How do I find out what kind of exception was thrown?

Update:
Learning the details of the exception from the Debugger Console was enough to help me solve the problem. (See http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=en.) I verified that I could set a symbolic breakpoint on objc_exception_throw, but I didn't look to see if the backtrace from there would have been helpful.

like image 223
Daryl Spitzer Avatar asked Dec 21 '08 18:12

Daryl Spitzer


People also ask

How do I debug Xcode on iPhone?

To try to debug it, set your active scheme in Xcode to be AppName > iPhone 11 Pro Max. Then using the simulator alone (not Xcode) click on the AppName to let it run. Then go into Xcode and do Debug > Attach to process by PID. Then type in the name of your App, and click Attach.

What is exception breakpoint in Xcode?

An exception breakpoint is a type of breakpoint that is created when some exception occurs in the code. On occurrence of such exception our application stops at that given condition causing the exception and we can access all variables in scope at that breakpoint.

How do I show debugger 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.


2 Answers

Put a breakpoint at objc_exception_throw and run your app via Debug instead of Run

To clarify, what you're actually seeing when you get an exception without the breakpoint is the same stack trace always - it's the uncaught exception handler. The type of exception is logged to the Run console, but if you want to see a backtrace for where the exception was raised, that's what the breakpoint is for.

like image 66
Lily Ballard Avatar answered Sep 26 '22 03:09

Lily Ballard


In the new Xcode (at least starting from v4.5), you can catch all exceptions easily by doing this:

  1. Bring up breakpoint navigator (⌘6)
  2. Click + on the bottom left
  3. Add Exception Breakpoint

I think the above is the same as a breakpoint on objc_exception_throw. http://samwize.com/2012/09/26/xcode-4-dot-5-tips-and-tricks/

like image 26
samwize Avatar answered Sep 23 '22 03:09

samwize