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

后端 未结 6 829
梦如初夏
梦如初夏 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条回答
  •  粉色の甜心
    2021-02-09 01:57

    I'm a big fan of the out error approach that Objective-C uses. You HAVE to handle exceptions, but you can choose to ignore out errors if you want to. It all fits with the Objective-C attitude that "the programmer knows what they're doing." It also makes Objective-C a very clean-looking language, because your code isn't cluttered with try-catch blocks.

    That said - you might want to consider: Are there any scenarios where exceptions are ignored? Are the exceptions you throw truly critical? Do you find yourself writing simple catch blocks that clean up variables and continue on? I'd lean toward out errors because I like the syntax and Objective-C reserves exceptions for only the most critical errors.

提交回复
热议问题