Defined Exception Handling Exception Handling is used to overcome exceptions that take place during programs’ execution in a systematic manner. For instance, dividing a number by ‘0’ is a mathematical error (not defined). As you learned in class, you can use exception handling to overcome such operations. If you write a code without using exception handling, then the output of division by zero will be shown as infinity which cannot be further processed. Consider the following code: float Division(float num, float den) {return (num / den);} int main() { float numerator = 12.5; float denominator = 0; float result; result = Division(numerator, denominator); cout << "The quotient of 12.5/0 is " << result << endl; }
Defined Exception Handling
Exception Handling is used to overcome exceptions that take place during programs’ execution in a systematic manner.
For instance, dividing a number by ‘0’ is a mathematical error (not defined). As you learned in class, you can use exception handling to overcome such operations. If you write a code without using exception handling, then the output of division by zero will be shown as infinity which cannot be further processed. Consider the following code:
float Division(float num, float den)
{return (num / den);}
int main() {
float numerator = 12.5;
float denominator = 0;
float result;
result = Division(numerator, denominator);
cout << "The quotient of 12.5/0 is "
<< result << endl;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images