Hi there

My .asp application draws data from a number of sources, converts the
results to type.double and does various calculations with these figures.
Because of data entry errors on the system from which some of the data is
drawn (this system is unfortunately not under my control so I can not sort
this problem out at source....) I occasionally get Divide by Zero Exceptions
which crash my application.

Does anyone have a clever (or otherwise) way of catching this particular
error and inserting a value of 0 in to the result instead of crashing ?

Any help would be appreciated

Re: Divide by Zero exception by Marina

Marina
Wed May 25 10:48:38 CDT 2005

When you are doing your calculations, check if you are dividing by something
that is zero, and handle apropriately. The lazier way to do this would be to
put a Try/catch around the calculations and specificly handle
DivdeByZeroException and put a zero in instead in the catch block.

"Stuart" <Stuart@discussions.microsoft.com> wrote in message
news:FCD6D939-37D1-4A50-87B8-414AD9EDAF69@microsoft.com...
> Hi there
>
> My .asp application draws data from a number of sources, converts the
> results to type.double and does various calculations with these figures.
> Because of data entry errors on the system from which some of the data is
> drawn (this system is unfortunately not under my control so I can not sort
> this problem out at source....) I occasionally get Divide by Zero
> Exceptions
> which crash my application.
>
> Does anyone have a clever (or otherwise) way of catching this particular
> error and inserting a value of 0 in to the result instead of crashing ?
>
> Any help would be appreciated



Re: Divide by Zero exception by Sahil

Sahil
Wed May 25 17:19:04 CDT 2005

I am assuming since you posted this in an ADONET NG< your data resides in a
datatable?

Bad but obvious solution -
Put a try catch block - catch DivideByZeroException.
Better but not so obvious solution -
Use the RowAdded event on the datatable to "clean" the data as it is being
filled - so if you see a null, put a zero in there.

- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/



"Stuart" <Stuart@discussions.microsoft.com> wrote in message
news:FCD6D939-37D1-4A50-87B8-414AD9EDAF69@microsoft.com...
> Hi there
>
> My .asp application draws data from a number of sources, converts the
> results to type.double and does various calculations with these figures.
> Because of data entry errors on the system from which some of the data is
> drawn (this system is unfortunately not under my control so I can not sort
> this problem out at source....) I occasionally get Divide by Zero
Exceptions
> which crash my application.
>
> Does anyone have a clever (or otherwise) way of catching this particular
> error and inserting a value of 0 in to the result instead of crashing ?
>
> Any help would be appreciated