"try" expression function not working as expected

Hello everybody,

I am experiencing this strange behaviour with a “try” expression function on an expression tag where I would expect the failover value to be returned, instead tha tag goes in error “Error_TypeConversion”.

I’m attaching some screenshots, maybe someone has alredy gone through this or maybe I’m doing something wrong.

Thanks for the help


Supply 0.0 as your failover value.

Hi pturmel,

thanks for the suggestion, sadly it didn’t work.
I think it’s also because if you see the error message in the tag diagnostic details, it looks like the error is returned from the math formula, not from the failover.

Can you supply all your tag values (and data types) that are used in the expression?

The values are all Float type. They can change depending on what the machine is doing, so it could also happen that all the values are 0.

It seems to me that the main problem is that the try function is not working properly, because I would expect it to handle every type of exception inside the formula.

Make a bunch of expressions, one for each inner piece of this expression, then more for each built-up fragment, until you find the problem.

2 Likes

Dividing by zero does not return an error, because the result is Infinite or NaN. Replace try with min.
Example: min((32.0 / 0), 0.0) returns 0.0

That said, you should be testing your values before the calculation is done.

2 Likes

Thanks Jordan the min function did the job.

Before using the min function I’ve tried to change my tag type from float to string and the result was NaN so I guess the error was happening after the formula elaboration, even after the try function. Simply when the expression output tried to write NaN to a float tag then it couldn’t convert it.

Do you think that writing a formula without testing the values is less efficient in cases like mine, rather then testing every value with an if, min, max ecc?

It’s more of a sanity check than efficiency. If any of your later values are zero, you certainly don’t want to divide a number by it. It’s the root cause that started your thread. :slight_smile: