@try - catch block in Objective-C

后端 未结 3 712
旧时难觅i
旧时难觅i 2020-12-07 11:44

Why doesn\'t @try block work? It crashed the app, but it was supposed to be caught by the @try block.

 NSString* test = [NSString stringWithString:@\"ss\"];
         


        
3条回答
  •  情歌与酒
    2020-12-07 12:33

    Objective-C is not Java. In Objective-C exceptions are what they are called. Exceptions! Don’t use them for error handling. It’s not their proposal. Just check the length of the string before using characterAtIndex and everything is fine....

提交回复
热议问题