-Improve OverflowException message for integer values larger than an Int64
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user