2
// Copyright (c) 2007 James Newton-King
4
// Permission is hereby granted, free of charge, to any person
5
// obtaining a copy of this software and associated documentation
6
// files (the "Software"), to deal in the Software without
7
// restriction, including without limitation the rights to use,
8
// copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following
13
// The above copyright notice and this permission notice shall be
14
// included in all copies or substantial portions of the Software.
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
// OTHER DEALINGS IN THE SOFTWARE.
27
using System.Collections.Generic;
28
using System.Globalization;
29
using System.Runtime.Serialization;
31
using Newtonsoft.Json.Utilities;
33
namespace Newtonsoft.Json
36
/// The exception thrown when an error occurs during Json serialization or deserialization.
38
#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE || PORTABLE)
41
public class JsonException : Exception
44
/// Initializes a new instance of the <see cref="JsonException"/> class.
46
public JsonException()
51
/// Initializes a new instance of the <see cref="JsonException"/> class
52
/// with a specified error message.
54
/// <param name="message">The error message that explains the reason for the exception.</param>
55
public JsonException(string message)
61
/// Initializes a new instance of the <see cref="JsonException"/> class
62
/// with a specified error message and a reference to the inner exception that is the cause of this exception.
64
/// <param name="message">The error message that explains the reason for the exception.</param>
65
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
66
public JsonException(string message, Exception innerException)
67
: base(message, innerException)
71
#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE || PORTABLE)
73
/// Initializes a new instance of the <see cref="JsonException"/> class.
75
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
76
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
77
/// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception>
78
/// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception>
79
public JsonException(SerializationInfo info, StreamingContext context)
85
internal static string FormatExceptionMessage(IJsonLineInfo lineInfo, string path, string message)
87
// don't add a fullstop and space when message ends with a new line
88
if (!message.EndsWith(Environment.NewLine))
90
message = message.Trim();
92
if (!message.EndsWith("."))
98
message += "Path '{0}'".FormatWith(CultureInfo.InvariantCulture, path);
100
if (lineInfo != null && lineInfo.HasLineInfo())
101
message += ", line {0}, position {1}".FormatWith(CultureInfo.InvariantCulture, lineInfo.LineNumber, lineInfo.LinePosition);
b'\\ No newline at end of file'