Is there any way to catch format exception here besides using a try-catch statement? If user inputs anything more than a single character, it gives format exception. This is my code:
public void Menu()
{
Console.WriteLine("Would you like to play RPS? y/n");
char playOrNot = Convert.ToChar(Console.ReadLine());
while(!validateChoice(playOrNot))
{
Console.WriteLine("Invalid! please re-enter selection");
playOrNot = Convert.ToChar(Console.ReadLine());
}
if (playOrNot == 'Y' || playOrNot == 'y')
{
Console.Clear();
PlayGame();
}
}
public bool validateChoice(char playornot)
{
if (char.ToUpper(playornot) != 'Y' && char.ToUpper(playornot) != 'N')
return false;
return true;
}