How to do a try catch in c# so that I execute a sql query inside the try catch
Sometimes the value of count is 0, and it throws a error divide by zero error. So when it throws the divide by zero error I have to execute a sql statement to delete that statement and and the loop has to continue to get the value of the next record. How can i do it.
double value = (read * 100 / count);
Why doing a try/catch when you can simply test whether the value of count
is equal to 0:
if (count != 0)
{
// perform the division only if count is different than 0,
// otherwise we know that it will throw an exception
// so why even attempting it?
double value = (read * 100 / count);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With