1

EXC_BAD_ACCESS is a trouble but it does improve the newbie experience regarding memory. I am a C programer improvising to iOS development.

  1. What is EXC_BAD_ACCESS concept in terms of memory ?
  2. Why it can't be caught in catch block, Is it not a run time exception though it incur at run time.?
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

1

EXC_BAD_ACCESS occurs when something that caused a pointer (yours, one internal to the iPhone, or one that the allocator is using) to be dereferenced and that memory location isn’t inside one of the chunks assigned to your program.

This could be because

  • The pointer used to point to memory that was ok, but its chunk was deallocated.
  • The pointer is corrupt.

And try-catch style exceptions are non-recoverable in iOS/Cocoa. Exceptions are not to be used for recoverable error handling . Check this one Is there a way to catch or handle EXC_BAD_ACCESS?.

Community
  • 1
  • 1
Yatheesha
  • 10,412
  • 5
  • 42
  • 45
  • 2
    Some exception are catchable and some are recoverable and some should be caught so the app doesn't crash. It depends on the nature of the exception. Of course `EXC_BAD_ACCESS` isn't one of them. – rmaddy Jul 04 '14 at 04:47
  • 1
    Re "try-catch style exceptions are non-recoverable in iOS/Cocoa." - What do you mean by "non-recoverable"? iOS has `@try`, `@catch`, and `@finally` - these provide "recovery" from (some) exceptions, just like any other modern language. Are you referring to the fact that *certain* "exceptions" (such as `EXC_BAD_ACCESS`) can't be caught? AFAIK that is independent of the discussion as to when/whether it is appropriate to use exceptions oneself. – ToolmakerSteve Jan 31 '17 at 02:39