~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/Newtonsoft.Json/Src/Newtonsoft.Json/JsonReaderException.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region License
 
2
// Copyright (c) 2007 James Newton-King
 
3
//
 
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
 
11
// conditions:
 
12
//
 
13
// The above copyright notice and this permission notice shall be
 
14
// included in all copies or substantial portions of the Software.
 
15
//
 
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.
 
24
#endregion
 
25
 
 
26
using System;
 
27
using System.Globalization;
 
28
using System.Runtime.Serialization;
 
29
using Newtonsoft.Json.Utilities;
 
30
 
 
31
namespace Newtonsoft.Json
 
32
{
 
33
  /// <summary>
 
34
  /// The exception thrown when an error occurs while reading Json text.
 
35
  /// </summary>
 
36
#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE || PORTABLE)
 
37
  [Serializable]
 
38
#endif
 
39
  public class JsonReaderException : JsonException
 
40
  {
 
41
    /// <summary>
 
42
    /// Gets the line number indicating where the error occurred.
 
43
    /// </summary>
 
44
    /// <value>The line number indicating where the error occurred.</value>
 
45
    public int LineNumber { get; private set; }
 
46
 
 
47
    /// <summary>
 
48
    /// Gets the line position indicating where the error occurred.
 
49
    /// </summary>
 
50
    /// <value>The line position indicating where the error occurred.</value>
 
51
    public int LinePosition { get; private set; }
 
52
 
 
53
    /// <summary>
 
54
    /// Gets the path to the JSON where the error occurred.
 
55
    /// </summary>
 
56
    /// <value>The path to the JSON where the error occurred.</value>
 
57
    public string Path { get; private set; }
 
58
 
 
59
    /// <summary>
 
60
    /// Initializes a new instance of the <see cref="JsonReaderException"/> class.
 
61
    /// </summary>
 
62
    public JsonReaderException()
 
63
    {
 
64
    }
 
65
 
 
66
    /// <summary>
 
67
    /// Initializes a new instance of the <see cref="JsonReaderException"/> class
 
68
    /// with a specified error message.
 
69
    /// </summary>
 
70
    /// <param name="message">The error message that explains the reason for the exception.</param>
 
71
    public JsonReaderException(string message)
 
72
      : base(message)
 
73
    {
 
74
    }
 
75
 
 
76
    /// <summary>
 
77
    /// Initializes a new instance of the <see cref="JsonReaderException"/> class
 
78
    /// with a specified error message and a reference to the inner exception that is the cause of this exception.
 
79
    /// </summary>
 
80
    /// <param name="message">The error message that explains the reason for the exception.</param>
 
81
    /// <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>
 
82
    public JsonReaderException(string message, Exception innerException)
 
83
      : base(message, innerException)
 
84
    {
 
85
    }
 
86
 
 
87
#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE || PORTABLE)
 
88
    /// <summary>
 
89
    /// Initializes a new instance of the <see cref="JsonReaderException"/> class.
 
90
    /// </summary>
 
91
    /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
 
92
    /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
 
93
    /// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception>
 
94
    /// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception>
 
95
    public JsonReaderException(SerializationInfo info, StreamingContext context)
 
96
      : base(info, context)
 
97
    {
 
98
    }
 
99
#endif
 
100
 
 
101
    internal JsonReaderException(string message, Exception innerException, string path, int lineNumber, int linePosition)
 
102
      : base(message, innerException)
 
103
    {
 
104
      Path = path;
 
105
      LineNumber = lineNumber;
 
106
      LinePosition = linePosition;
 
107
    }
 
108
 
 
109
    internal static JsonReaderException Create(JsonReader reader, string message)
 
110
    {
 
111
      return Create(reader, message, null);
 
112
    }
 
113
 
 
114
    internal static JsonReaderException Create(JsonReader reader, string message, Exception ex)
 
115
    {
 
116
      return Create(reader as IJsonLineInfo, reader.Path, message, ex);
 
117
    }
 
118
 
 
119
    internal static JsonReaderException Create(IJsonLineInfo lineInfo, string path, string message, Exception ex)
 
120
    {
 
121
      message = JsonPosition.FormatMessage(lineInfo, path, message);
 
122
 
 
123
      int lineNumber;
 
124
      int linePosition;
 
125
      if (lineInfo != null && lineInfo.HasLineInfo())
 
126
      {
 
127
        lineNumber = lineInfo.LineNumber;
 
128
        linePosition = lineInfo.LinePosition;
 
129
      }
 
130
      else
 
131
      {
 
132
        lineNumber = 0;
 
133
        linePosition = 0;
 
134
      }
 
135
 
 
136
      return new JsonReaderException(message, ex, path, lineNumber, linePosition);
 
137
    }
 
138
  }
 
139
}