P248 Exception is its own exception?


When we override UIViewController’s designated initializer to throw an exception, I’m getting a EXEC_BAD_ACCESS on the @throw line itself. This means that in the debugger I never see our exception name or reason.

I have:

  • Copied the code from the book download code (mine looked perfect, but I just wanted to be sure there wasn’t some typo in there I was blind to)
  • Looked up in the dev documentation the section on throwing exceptions – the code on Page 248 sure looks acceptable
  • Searched around the Internet for ideas on the exception I’m seeing (it’s a pretty common exception, but appears to be handling a situation where an object that has been deallocated is sent a message… I don’t see how that’s possible with this code a) it’s a compiler directive and b) the objects we need (the NSStrings for name and reason) are created in-line)
  • Built and run the version in the book download code, but it is provided in the state at the end of the chapter, so it’s beyond the lesson being taught in this section.

Reading ahead it looks like what’s being taught here is for the purpose of learning good programming practices; that when completed, the code we’re writing won’t ever call this init method so I can just forge ahead. But I consider learning about exceptions to be in the style of the book’s “challenges” and deeper understanding, so if anyone has any thoughts on what I should be investigating here, I’m all ears!

This is in Xcode 4.2 targeting an iPad 2 running iOS 5, using ARC.


Hm. Can you paste your @throw line? I wonder if this has to do with a bug in the beta.


Hi, I am having the same issue. Running 4.2.1


I think this may be a bug in Xcode - they really screwed up exception handling and reporting in the new version of Xcode. The code is right, and will work in the future.