Monday, July 4, 2011

What cause EXC_BAD_ACCESS and other EXC_BAD_XXX errors happen?

EXC_BAD_ACCESS and some similar errors are common to iOS developer. You never met one? Oh, god, you are the god, u don't need to read this post.

I, Tonny, as an extremely normal iOS programmer, EXC_BAD_XXX error is the most familiar error I meet everyday. But WHAT the hell cause these boring error messages? I don't want to dig too much deep, I just want to know what's the most likely reason cause each non-human readable error.

The lucky thing is Apple explained some of them many years ago, the unlucky thing is without search engine, you won't be able to find this document. And what's the most lucky thing is we have google(bing can also find this document). It can help a little.
  • EXC_BAD_ACCESS/KERN_INVALID_ADDRESS — This is caused by the thread accessing unmapped memory. It may be triggered by either a data access or an instruction fetch; the Thread State section describes how to tell the difference.
  • EXC_BAD_ACCESS/KERN_PROTECTION_FAILURE — This is caused by the thread trying to write to read-only memory. This is always caused by a data access.
  • EXC_BAD_INSTRUCTION — This is caused by the thread executing an illegal instruction.
  • EXC_ARITHMETIC/EXC_I386_DIV — This is caused by the thread doing an integer divide by zero on an Intel-based computer. 
  • Source:
You see? This tech note was published in 2004! that's 7 years ago on the very beginning that Apple started to ship Mac with Intel inside.  Why I say "very beginning", because Apple publicly announced it would ship new Mac with Intel's CPU on 2005[Source:Wiki].

And also, EXC_BAD_ACCESS has 2 meanings! Usually on iOS device, EXC_BAD_ACCESS is caused by accessing released object, but obviously, it has much more meanings than we expected.

Hope I can update this post later for more detailed information about any EXC_BAD_XXX error message.

No comments:

Post a Comment