I am trying to create a command-line application that searches through a directory of song names and albums input by the user and then plays that song. When the user inputs a non-existing song name or album, the program throws a DriectoryNotFoundException.
I have put the "song grabber" function within the try block and then if a user inputs an invalid directory, it goes to the catch block and tries again. It works as intended, yet only once. I have tried putting a while loop to make sure the try/catch function keeps working until the program fully succeeds.
while (true)
{
try
{
MusicSelector.SongGrabber();
break;
}
catch (System.IO.DirectoryNotFoundException)
{
Console.WriteLine("Enter the exact song names and album.");
MusicSelector.SongGrabber();
}
}
What should I do in order to retry until the user inputs a valid directory?