Is there any way to disable all thrown exceptions in iOS market release?

Viewed 64

Working on an iOS app. Apart from deciding whether it is right action or not, is there any way to disable all exception (which are thrown) in iOS market release? So that it will act like, all exceptions will be received in a common block which will do nothing.

1 Answers

You can apply a 'catch-all' exception handler using NSSetUncaughtExceptionHandler, which you call by passing a closure, e.g:

NSSetUncaughtExceptionHandler { exception in
  print("Uncaught exception: \(exception)")
}

A decent place to put this code would be in application:didFinishLaunchingWithOptions. That being said, it's probably a better idea to protect specific parts of the code which may fail with try/catch blocks in which you can mitigate the problems and prevent the app from getting into undefined states.

Related