Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
error handling!
  • Loading branch information
krb11010 committed Oct 5, 2020
1 parent 93449c4 commit 1a452f9
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions NumberGuesser/Program.cs
Expand Up @@ -21,15 +21,31 @@ namespace NumberGuesser
// Totally acceptable way to convert string to int
// int responseNumber = Convert.ToInt32(response);

// Fancy way to convert string to integer
int responseNumber;
bool success = int.TryParse(response, out responseNumber);
if (success == false)
//// Fancy way to convert string to integer
//int responseNumber;
//bool success = int.TryParse(response, out responseNumber);
//if (success == false)
//{
// Console.WriteLine("Invalid input!");
// continue;
//}

int responseNumber = 0;
try
{
responseNumber = Convert.ToInt32(response);
}
catch (Exception ex)
{
// Do stuff in case it fails
Console.WriteLine("Invalid input!");
Console.WriteLine(ex.Message);
continue;
}

finally
{
Console.WriteLine("Does this execute?");
}

responseHistory.Add(responseNumber);

Expand Down

0 comments on commit 1a452f9

Please sign in to comment.