When porting Java code to ObjC, how best to represent checked exceptions?

后端 未结 6 842
梦如初夏
梦如初夏 2021-02-09 01:08

I am working on porting a Java codebase to Cocoa/Objective-C for use on desktop Mac OS X. The Java code has lots and lots of methods with checked exceptions li

6条回答
  •  猫巷女王i
    2021-02-09 01:42

    In Cocoa, exceptions are really only supposed to be used for "programming errors;" the philosophy is to let the app catch them, give the user the option to save what they're doing, and quit. For one thing, not all frameworks or code paths may be 100% exception-safe, so this can be the only safe course of action. For errors that can be anticipated and recovered from, you should use NSError, typically via an out-parameter.

提交回复
热议问题