Since you don't tell us what input you give to your program, I can only guess:
You type something that cin can't parse as the sequence inputNumerator >> slash >> inputDenominator
, so it goes into a fail state or bad state. The exception gets thrown in the else branch of your function (you can and should test that by printing the exception's message in your main function's catch block).
Your loop in main goes on, but cin
is left in the bad state, so every following input fails again and the same exception is thrown again and again. To prevent that you should clear the state of cin during the error handling. In addition, if there are bad characters in the input stream that can't be parsed, they have to be thrown out, or ignore
d:
if ((std::cin >> inputNumerator >> slash >> inputDenominator) && slash == '/')
{
/* ... */
}
else
{
std::cin.clear(); // reset the fail flags
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //ignore the bad input until line end
throw std::invalid_argument("Invalid syntax.");
}