I've been working with exceptions in Object Programming for C++, and it's been easy thus far, but I've been struggling to understand my first assignment. I'm suppose to simply add a try-block and catch-block to this and make it so the program will work correctly.. I know how to do that, but I don't know what the exception is. When I run the program, after inputting a number, it runs infinitely, but I'm not sure what kind of error that is.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
int main()
{
double number, power;
cout<<"\nEnter a number: "; cin>>number;
for(longlong k=1;; k+=100)
{
power = pow(number,k);
cout<<"\nResult: "<<number<<"^"<<k<<"="<<power<<endl;
}
cout<<endl;
system("pause");
return 0;
}
If the base is finite negative and the exponent is finite but not an integer value, it causes a domain error.
If both base and exponent are zero, it may also cause a domain error on certain implementations.
If base is zero and exponent is negative, it may cause a domain error or a pole error (or none, depending on the library implementation).
The function may also cause a range error if the result is too great or too small to be represented by a value of the return type.