-Improve OverflowException message for integer values larger than an Int64

This commit is contained in:
JamesNK
2010-04-25 07:26:01 +00:00
parent 7085a4915f
commit 6c817fee93
2 changed files with 18 additions and 1 deletions
@@ -1479,5 +1479,14 @@ Parameter name: arrayIndex")]
string name = (string)o.Property("responseData");
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "JSON integer 307953220000517141511 is too large or small for an Int64.")]
public void NumberTooBigForInt64()
{
string json = @"{""code"": 307953220000517141511}";
JObject.Parse(json);
}
}
}
+9 -1
View File
@@ -708,7 +708,15 @@ namespace Newtonsoft.Json
}
else
{
numberValue = Convert.ToInt64(number, CultureInfo.InvariantCulture);
try
{
numberValue = Convert.ToInt64(number, CultureInfo.InvariantCulture);
}
catch (OverflowException ex)
{
throw new JsonReaderException("JSON integer {0} is too large or small for an Int64.".FormatWith(CultureInfo.InvariantCulture, number), ex);
}
numberType = JsonToken.Integer;
}