 |
|

Given the following code, how could we write the function openFile so that it correctly throws an exception if the file does not open correctly?
void main()
{
ifstream f;
int num1, num2, val;
try {
openFile(f);
cout << "The numbers are:" << endl;
while (!f.eof()) {
f >> num1;
f >> num2;
if (num2==0) {
throw("divide by zero");
}
val = num1/num2;
cout << val << endl;
}
f.close();
}
catch (char *s) {
cout << "There was error: " << s << endl;
}
}
|
 |
| |
|
|
 |