I am trying to add an exception handler for Dividing by zero, however if the if is TRUE, it crashes the program. any help would be appreciated
Here is the snippet that I am getting the error at..
mid4 = mid1-1;//this is the sum of the previous formula times number of months minus 1
{
if (mid4 == 0)// Checks the mid4 int to deduce whether it is zero or not.
throw std::overflow_error("Divide by zero exception");
}
mid5 = mid2 / mid4;// this is the figuring of the mortgage amount
Thank you, I added the Catch... but still crashing. I have to admit, I am a little confused on how this is processing. Thanks in advance for any help
mid4 = mid1-1;//this is the sum of the previous formula times number of months minus 1
{
if (mid4 == 0)// Checks the mid4 int to deduce whether it is zero or not.
throw std::overflow_error("Divide by zero exception");
}
Thank you LB, I read that, and I am still trying to understand what the process is, In my program, if mid4 is 0, I want it to throw and exception. I think part of my issue is placement, does it have to be placed at the moment in the program, before something is divided by mid4? and do I have to create the Try area prior to that? So like
Try {
if (mid4 == 0)// Checks the mid4 int to deduce whether it is zero or not.
throw std::overflow_error("Divide by zero exception");
}
Catch (std::overflow_error e)
{ cout << e.what();}
cout << mid4 << endl;
mid5 = mid2 / mid4