Hello programmers!
I am working on a Tic-Tac-Toe player vs. computer class, which is supposed to have a run.()
method in order for the game to start. In a gameWon()
member function, I am checking for a win, either by the player or by the computer. I check to see if a row was won, if a column was won, and if a diagonal was won. With each scenario, a private member function is called that returns a bool
. In my diagonalWon()
function, I check to see if I have an equal number of rows and columns, which means that there are two diagonals avaliable. However, if the number of rows doesn't equal the number of columns, I want an error to be raised that terminates the function execution. My code is below:
bool TicTacToe::diagonalWon()
{
//checks to se if player won using the diagonals
try
{
//check to see if there are diagonals
if (rows!=columns)
{
//there are no diagonals. throw exception #1
throw 1;
}
else
{
//continue to check if the diagonals are won
}
}
catch(exception)
{
cerr << "\n\nERROR in diagonalWon"<<endl;
return nullptr;
}
}
However, I get an xCode message that the control may reach the end of a non-void function
. How can I successfuly raise the error, which in reply to exception #1 prints: There are no diagonals
, while eliminating the message successfully?