Console.WriteLine("Amount Spent (0.00):");
float amount;
string amountString;
bool repeat = false;
do
{
repeat = false;
amountString = Console.ReadLine();
try
{
amount = float.Parse(amountString);
}
catch (FormatException)
{
Console.WriteLine("Numeric Value Required.");
repeat = true;
}
catch (OverflowException)
{
Console.WriteLine("Number too large/small for float.");
repeat = true;
}
catch (Exception)
{
Console.WriteLine("Invalid Input.");
repeat = true;
}
}
while (repeat);
return float.Parse(amountString);
This Code works fine for regular numbers, however if I start entering ridiculously big numbers I get a returned value of 8. I would of expected the OverFlowException to catch a number too large. Shouldn't it catch them?
If I type in:
50000000000000000000000000000000000000
I get values such as 5E+37 which is think is to do with precision, but i expect this. But with one digit longer it just returns 8. i assume this is because it is too large but i would of thought the OverflowException in the tryCatch should catch it shouldn't it?