Total noob here, still trying to learn C# ... not sure where this exception is being thrown. I'm not seeing it in output and the program compiles and runs flawlessly.
EDIT: By flawlessly I mean the code compiles, runs, does what it needs to do, and exits appropriately without crashing.
EDIT2: More information: this is for an online class and I don't see the exception thrown in visual studio but when I paste my code into their on site answer block and have it check the work it throws the exception which is making it difficult to locate the source. The output window in VS isn't returning the ArgumentNullException.
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
while (true)
{
try
{
string times = Console.ReadLine();
int repeater = int.Parse(times);
while (repeater > 0)
{
Console.WriteLine("Yay!");
repeater--;
}
break;
}
catch (FormatException)
{
Console.WriteLine("You must enter a whole number!");
}
}
Console.ReadLine();
}
EDIT3: FINALLY got this error from the school's compiler:
System.ArgumentNullException: Value cannot be null.
Parameter name: String
at System.Number.StringToNumber (System.String str, NumberStyles options, System.NumberBuffer& number, System.Globalization.NumberFormatInfo info, Boolean parseDecimal) [0x00054] in /builddir/build/BUILD/mono-4.4.2/external/referencesource/mscorlib/system/number.cs:1074
at System.Number.ParseInt32 (System.String s, NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in /builddir/build/BUILD/mono-4.4.2/external/referencesource/mscorlib/system/number.cs:745
at System.Int32.Parse (System.String s) [0x00000] in /builddir/build/BUILD/mono-4.4.2/external/referencesource/mscorlib/system/int32.cs:120
at Treehouse.CodeChallenges.Program.Main () <0x41076f10 + 0x0004e> in :0
at MonoTester.Run () [0x00197] in MonoTester.cs:125
at MonoTester.Main (System.String[] args) [0x00013] in MonoTester.cs:28
Exercise instructions: Add input validation to your program by printing “You must enter a whole number.” if the user enters a decimal or something that isn’t a number. Hint: Catch the FormatException.