Our teacher gave us a list of code snippets to prepare for our final exam. For each one, we have to tell either the code compiles, and if so to guess what it outputs. Here is one of them:
#include <iostream>
using namespace std;
float f(int y){
try{
if(y % 2)
throw y / 2;
}
catch(int i){
if (i % 2) throw;
cout << "Number " << i << "is not good! " << "\n";
}
return y / 2;
}
int main(){
int x;
try{
cout << "Give me an integer: ";
cin >> x;
if(x) f(x);
cout << "Number " << x << " not good!\n";
}
catch(int i){
cout << "Number " << i << " is good ! " << "\n";
}
return 0;
}
What does that throw
(no argument) really do? Does it just re-throw the current exception, meaing "i"? Is there more I should now or understant from this example ?