Practice on Exceptions

Pages: 12
i thought that was another way to terminate the program :( but anyways the program does not print anything out when i run it.
The following code complies but it does not print anything out when i run it :(

That means it worked. There's nothing printing out the return of the function call (which is missing, btw).
but anyways the program does not print anything out when i run it.

You didn't ask it to. As it is, it will only output anything if you pass invalid data to computeAge() and the exception is thrown.
How would i fix it so it will print something out?
1
2
3
4
5
6
try
    {
        computeAge(1950, 1990);
    }
    catch (InvalidArgumentException& e) 
    {


I switched the values around
Last edited on
You need to finish this:
1
2
3
4
5
6

int computeAge(int currentYear, int birthDate)
{
 if (currentYear < 0 || birthDate < 0 || currentYear < birthDate)
                   throw InvalidArgumentException();
}

because it doesn't actually compute anything.
Topic archived. No new replies allowed.
Pages: 12