-Added Path to JsonReaderException/JsonSerializationException messages
-Added JsonException -Fixed all Exceptions thrown to be more specific
This commit is contained in:
@@ -79,7 +79,7 @@ namespace Newtonsoft.Json.Converters
|
||||
if (value is SqlBinary)
|
||||
return ((SqlBinary) value).Value;
|
||||
|
||||
throw new Exception("Unexpected value type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
|
||||
throw new JsonSerializationException("Unexpected value type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,7 +99,7 @@ namespace Newtonsoft.Json.Converters
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
{
|
||||
if (!ReflectionUtils.IsNullable(objectType))
|
||||
throw new Exception("Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
throw JsonSerializationException.Create(reader, "Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -119,7 +119,7 @@ namespace Newtonsoft.Json.Converters
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unexpected token parsing binary. Expected String or StartArray, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected token parsing binary. Expected String or StartArray, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Newtonsoft.Json.Converters
|
||||
if (t == typeof(SqlBinary))
|
||||
return new SqlBinary(data);
|
||||
|
||||
throw new Exception("Unexpected object type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected object type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
}
|
||||
|
||||
private byte[] ReadByteArray(JsonReader reader)
|
||||
@@ -151,11 +151,11 @@ namespace Newtonsoft.Json.Converters
|
||||
// skip
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unexpected token when reading bytes: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected token when reading bytes: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("Unexpected end when reading bytes.");
|
||||
throw JsonSerializationException.Create(reader, "Unexpected end when reading bytes.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Newtonsoft.Json.Converters
|
||||
while (reader.TokenType == JsonToken.Comment)
|
||||
{
|
||||
if (!reader.Read())
|
||||
throw new Exception("Unexpected end.");
|
||||
throw JsonSerializationException.Create(reader, "Unexpected end when reading ExpandoObject.");
|
||||
}
|
||||
|
||||
switch (reader.TokenType)
|
||||
@@ -57,7 +57,7 @@ namespace Newtonsoft.Json.Converters
|
||||
if (JsonReader.IsPrimitiveToken(reader.TokenType))
|
||||
return reader.Value;
|
||||
|
||||
throw new Exception("Unexpected token when converting ExpandoObject: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected token when converting ExpandoObject: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Newtonsoft.Json.Converters
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("Unexpected end.");
|
||||
throw JsonSerializationException.Create(reader, "Unexpected end when reading ExpandoObject.");
|
||||
}
|
||||
|
||||
private object ReadObject(JsonReader reader)
|
||||
@@ -96,7 +96,7 @@ namespace Newtonsoft.Json.Converters
|
||||
string propertyName = reader.Value.ToString();
|
||||
|
||||
if (!reader.Read())
|
||||
throw new Exception("Unexpected end.");
|
||||
throw JsonSerializationException.Create(reader, "Unexpected end when reading ExpandoObject.");
|
||||
|
||||
object v = ReadValue(reader);
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Newtonsoft.Json.Converters
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("Unexpected end.");
|
||||
throw JsonSerializationException.Create(reader, "Unexpected end when reading ExpandoObject.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Newtonsoft.Json.Converters
|
||||
#endif
|
||||
else
|
||||
{
|
||||
throw new Exception("Unexpected value when converting date. Expected DateTime or DateTimeOffset, got {0}.".FormatWith(CultureInfo.InvariantCulture, ReflectionUtils.GetObjectType(value)));
|
||||
throw new JsonSerializationException("Unexpected value when converting date. Expected DateTime or DateTimeOffset, got {0}.".FormatWith(CultureInfo.InvariantCulture, ReflectionUtils.GetObjectType(value)));
|
||||
}
|
||||
|
||||
writer.WriteValue(text);
|
||||
@@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Converters
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
{
|
||||
if (!ReflectionUtils.IsNullableType(objectType))
|
||||
throw new Exception("Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
throw JsonSerializationException.Create(reader, "Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ namespace Newtonsoft.Json.Converters
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonToken.String)
|
||||
throw new Exception("Unexpected token parsing date. Expected String, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected token parsing date. Expected String, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
|
||||
string dateText = reader.Value.ToString();
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Newtonsoft.Json.Converters
|
||||
#endif
|
||||
else
|
||||
{
|
||||
throw new Exception("Expected date object value.");
|
||||
throw new JsonSerializationException("Expected date object value.");
|
||||
}
|
||||
|
||||
writer.WriteStartConstructor("Date");
|
||||
@@ -60,18 +60,18 @@ namespace Newtonsoft.Json.Converters
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
{
|
||||
if (!ReflectionUtils.IsNullableType(objectType))
|
||||
throw new Exception("Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
throw JsonSerializationException.Create(reader, "Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonToken.StartConstructor || !string.Equals(reader.Value.ToString(), "Date", StringComparison.Ordinal))
|
||||
throw new Exception("Unexpected token or value when parsing date. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected token or value when parsing date. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value));
|
||||
|
||||
reader.Read();
|
||||
|
||||
if (reader.TokenType != JsonToken.Integer)
|
||||
throw new Exception("Unexpected token parsing date. Expected Integer, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected token parsing date. Expected Integer, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
|
||||
long ticks = (long)reader.Value;
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Newtonsoft.Json.Converters
|
||||
reader.Read();
|
||||
|
||||
if (reader.TokenType != JsonToken.EndConstructor)
|
||||
throw new Exception("Unexpected token parsing date. Expected EndConstructor, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected token parsing date. Expected EndConstructor, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
|
||||
#if !PocketPC && !NET20
|
||||
if (t == typeof(DateTimeOffset))
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Newtonsoft.Json.Converters
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
{
|
||||
if (!isNullable)
|
||||
throw new Exception("Could not deserialize Null to KeyValuePair.");
|
||||
throw JsonSerializationException.Create(reader, "Cannot convert null value to KeyValuePair.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace Newtonsoft.Json.Converters
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
{
|
||||
if (!ReflectionUtils.IsNullableType(objectType))
|
||||
throw new Exception("Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
throw JsonSerializationException.Create(reader, "Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ namespace Newtonsoft.Json.Converters
|
||||
if (reader.TokenType == JsonToken.Integer)
|
||||
return ConvertUtils.ConvertOrCast(reader.Value, CultureInfo.InvariantCulture, t);
|
||||
|
||||
throw new Exception("Unexpected token when parsing enum. Expected String or Integer, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected token when parsing enum. Expected String or Integer, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -168,7 +168,7 @@ namespace Newtonsoft.Json.Converters
|
||||
string s;
|
||||
if (map.TryGetBySecond(n2, out s))
|
||||
{
|
||||
throw new Exception("Enum name '{0}' already exists on enum '{1}'."
|
||||
throw new InvalidOperationException("Enum name '{0}' already exists on enum '{1}'."
|
||||
.FormatWith(CultureInfo.InvariantCulture, n2, t.Name));
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Newtonsoft.Json.Converters
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Expected Version object value");
|
||||
throw new JsonSerializationException("Expected Version object value");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,12 +81,12 @@ namespace Newtonsoft.Json.Converters
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Error parsing version string: {0}".FormatWith(CultureInfo.InvariantCulture, reader.Value), ex);
|
||||
throw JsonSerializationException.Create(reader, "Error parsing version string: {0}".FormatWith(CultureInfo.InvariantCulture, reader.Value), ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unexpected token or value when parsing version. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value));
|
||||
throw JsonSerializationException.Create(reader, "Unexpected token or value when parsing version. Token: {0}, Value: {1}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType, reader.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1274,7 +1274,7 @@ namespace Newtonsoft.Json.Converters
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Cannot get an XML string value from token type '{0}'.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
throw JsonSerializationException.Create(reader, "Cannot get an XML string value from token type '{0}'.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user