Search code examples
iphonensexception

does iphone os framework throw NSException itself?


I know i can throw an NSException in my own code,does iphone os framework throw NSException itself? if it does,means that i should catch the NSExceptions from framework? I know Java throws Exceptions inner SDK,such as unchecked exceptions.


Solution

  • Exceptions thrown by the frameworks in iOS and Cocoa are indicative of unrecoverable errors. Exceptions are not used (outside of very extreme exceptions) to convey something like a validation problem.

    In general, iOS and Cocoa use NSError to convey recoverable problems (like user entry validation errors, state validation errors in Core Data, or connectivity issues, for examples).

    You should not use exceptions within your own code for purposes beyond indicating unrecoverable problems. It goes against the patterns of the underlying frameworks and doing so will make your code more difficult to evolve over time.