so I'm trying to catch a custom exception. It works fine but skips to the next line of the code without giving me a chance to retry. If I try it without a try-catch block it still works but terminates the program. I'd like for it to catch the custom exception then allow me to enter the correct input value. Thanks
Console.WriteLine("Please enter User Name: ");
try
{
user.userName = Console.ReadLine();
if(user.userName != "Papa")
{
throw new ArgumentException("User name doesn't exist");
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
try
{
Console.WriteLine("Please enter User Pin: ");
user.userPin = Convert.ToInt32(Console.ReadLine());
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
'try' does not mean 'keep trying until no exception'. It just means 'do this and if there is an exception go there'. You have to write a loop yourself
I would also say that I really dont like using an exception like that, to take a different logic path in side a single function. I would do