Monday, April 30, 2012

Tracking Down Exception Errors With objc_exception_throw in iPhone

When an application throws an exception, there is debug information shown in the console – below is the output in the console for an NSInvalidArgumentException:




Although helpful, depending on the size of your application, it may take quite some time to find the offending code. One way to better track exceptions is to catch them. However, wrapping every potential condition is not always practical. There is another way to track down exception errors.

With a symbolic breakpoint, we can force the runtime to stop on the line of code that is generating the exception. Select the breakpoint tab (in the Project navigator) and tap the + in the lower left corner to create a new symbolic breakpoint. Enter objc_exception_throw for theSymbol as shown below:




When you run the application with the symbolic breakpoint enabled, the code will stop at the offending line:





Notice in the console the reference to obj_exception_throw and Pending breakpoint – the debugger stops before the actual line of code executed.

When you experience an exception that is not wrapped in a try/catch block, give the symbolic breakpoint a go.

I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

[iPhone Development][iOS Development][Objective C Programming][iPhone]