0

I use NSAssert to detect unrecoverable conditions in my code. I enabled assertions in release mode as well because if an assertion fails in my code, it's guaranteed to be unrecoverable.

NSAssert raises NSInternalInconsistencyException and I've read conflicting posts about NSInternalInconsistencyException being caught by some frameworks and thus not crashing the app. Is this correct? I want my app to crash any time an NSAssert fails.

Will it also crash if thrown on background threads such as from a dispatch queue?

Monstieur
  • 7,992
  • 10
  • 51
  • 77

1 Answers1

0

It is my understanding (backed by experience) that NO exceptions are guaranteed to cause a crash. The system frequently catches them.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • I create a block local variable, don't initialize it to anything, and then invoke it. – Duncan C Mar 13 '15 at 14:41
  • Note that Apple takes a dim view of apps that crash themselves, and will probably reject you. You're supposed to display a message to the user about the problem and NOT crash/exit. – Duncan C Mar 13 '15 at 14:42
  • That would be a recoverable error and handled appropriately. Assertions would be for programming errors that will result in undefined behaviour such as `nil` pointer arguments. The app would never crash in production unless such an error slipped through testing, in which case a crash is preferable to silent data corruption. – Monstieur Mar 13 '15 at 14:57