Catching NSInvalidArgumentException from NSExpression

后端 未结 2 484
南旧
南旧 2021-01-22 15:21

In my code I am evaluating strings as mathematical expressions for example:

NSString *formula=@\"9*7\";
NSExpression *expr =[NSExpression expressionWithFormat:fo         


        
2条回答
  •  不思量自难忘°
    2021-01-22 16:07

    The reason this exception is not caught with your current code is that the exception is being thrown from this line:

    NSExpression *expr =[NSExpression expressionWithFormat:formula];
    

    You need to move this line into the @try block.

提交回复
热议问题