I use NSExpression to solve math formulas. Everthing works fine, if the input formula is correct, but if I input a formula like:
6-
My app gets terminated with the following error message:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "6- == 1"'
In Object-C it is possible to put this code into a @try block. Is there something equal in swift? Or how do I handle this Exceptions?
Here is my simple NSExpression code:
let expression = NSExpression(format: finalFormula)
if let result = expression.expressionValueWithObject(nil, context: nil) as? NSNumber {
return result
}
I solution would be to check the input first, but I would be OK for me if I get back nil or something like this.