It absolutely does something. It tells the rest of the program logic that the year is valid.
It does so in an unusual way.
Take a look at:
Code:
try {
year_ok(year) ;
day_ok(day, month, year) ;
cout << setfill('0') << "Date: " <<
setw(2) << month << "/" <<
setw(2) << day << "/" <<
setw(4) << year << " is valid" << endl ;
}
catch (...) {
cout << setfill('0') << "Date: " <<
setw(2) << month << "/" <<
setw(2) << day << "/" <<
setw(4) << year << " is not valid" << endl ;
}
In the code above, we have two branches of logic. If the year is okay and the day is okay, we print the date with "is valid". Otherwise, we print the date with "is not valid". But the control flow is determined by whether or not year_ok or day_ok throws an exception. I daresay that this is akin to the use of goto. It would be clearer to write:
Code:
if (isValidDate(day, month, year))
{
cout << setfill('0') << "Date: " <<
setw(2) << month << "/" <<
setw(2) << day << "/" <<
setw(4) << year << " is valid" << endl ;
}
else
{
cout << setfill('0') << "Date: " <<
setw(2) << month << "/" <<
setw(2) << day << "/" <<
setw(4) << year << " is not valid" << endl ;
}