How do I handle dividing by zero?
Question

Hi everybody,

I have built a report page where I have a couple of expressions to calculate (for example) the average age of my employees, the average amount of hours they work per week etc. and I made it possible for the end-user to specify a quarter for which they would like to see the data. However, for some quarters there is simply no data yet, which means the results are divided by zero, generating the following message:


How do I handle the exception so that this message does not show?

Hi Lotte,

can you show the Oml?

Putting an IF clause in the calculation, to set the result as "0" or empty when the quarter still have no data doesn't work?

Solution

Dear Lotte

Please do remember that you are using the application for front-end users and it is calculating the average on data selection. So, to calculate avg it says = (Sum of data) / (Count of data)


In some cases, you do not have data which throws 0 / 0 and exception occurs.


Here if your intention is only to avoid the message you can use what @Samiksha Manekar has advised and it may solve the problem.


But for the end user if no data will appear could be confusing and look like application bug. You should one condition of "No Data Found". So, if there is no data you should not run the Avg Operation but show the message of No Data Found. 


Read more about the exception handlers: https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Traditional_Web/Web_Logic_Tools/Exception_Handler


Please feel free to ask in case of any question.

Solution

if( quarter = 0 , 0 , yourcalculation)

Hi,

You can put Exception Handler with allException.

Hope this works.

thanks

Hi Lotte,

can you show the Oml?

Putting an IF clause in the calculation, to set the result as "0" or empty when the quarter still have no data doesn't work?

Hi,

You can put Exception Handler with allException.

Hope this works.

thanks

Solution

if( quarter = 0 , 0 , yourcalculation)

Solution

Dear Lotte

Please do remember that you are using the application for front-end users and it is calculating the average on data selection. So, to calculate avg it says = (Sum of data) / (Count of data)


In some cases, you do not have data which throws 0 / 0 and exception occurs.


Here if your intention is only to avoid the message you can use what @Samiksha Manekar has advised and it may solve the problem.


But for the end user if no data will appear could be confusing and look like application bug. You should one condition of "No Data Found". So, if there is no data you should not run the Avg Operation but show the message of No Data Found. 


Read more about the exception handlers: https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Traditional_Web/Web_Logic_Tools/Exception_Handler


Please feel free to ask in case of any question.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.