2005-12-05 Lluis Sanchez Gual <lluis@novell.com>
[mono.git] / mcs / class / System.XML / System.Xml / XmlException.cs
1 //
2 // XmlException.cs
3 //
4 // Author:
5 //   Jason Diamond (jason@injektilo.org)
6 //   Atsushi Enomoto (atsushi@ximian.com)
7 //
8 // (C) 2002 Jason Diamond  http://injektilo.org/
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Globalization;
32 using System.Runtime.Serialization;
33 using System.Security.Permissions;
34
35 namespace System.Xml
36 {
37         [Serializable]
38         public class XmlException : SystemException
39         {
40                 #region Fields
41
42                 int lineNumber;
43                 int linePosition;
44                 string sourceUri;
45
46                 #endregion
47
48                 #region Constructors
49
50 #if NET_1_0
51 #else
52                 public XmlException () 
53                         : base ()
54                 {
55                 }
56 #endif
57                 public XmlException (string message, Exception innerException) 
58                         : base (message, innerException)
59                 {
60                 }
61
62                 protected XmlException (SerializationInfo info, StreamingContext context)
63                         : base (info, context)
64                 {
65                         this.lineNumber = info.GetInt32 ("lineNumber");
66                         this.linePosition = info.GetInt32 ("linePosition");
67                         this.sourceUri = info.GetString ("sourceUri");
68                 }
69
70 #if NET_1_0
71                 internal XmlException (string message)
72 #else
73                 public XmlException (string message)
74 #endif
75                         : base (message)
76                 {
77                 }
78
79                 internal XmlException (IXmlLineInfo li, string sourceUri, string message) : base (message)
80                 {
81                         if (li != null) {
82                                 this.lineNumber = li.LineNumber;
83                                 this.linePosition = li.LinePosition;
84                         }
85                         this.sourceUri = sourceUri;
86                 }
87                 
88 #if NET_1_0
89                 internal XmlException (string message, Exception innerException, int lineNumber, int linePosition)
90 #else
91                 public XmlException (string message, Exception innerException, int lineNumber, int linePosition)
92 #endif
93                         : base (message, innerException)
94                 {
95                         this.lineNumber = lineNumber;
96                         this.linePosition = linePosition;
97                 }
98
99                 #endregion
100
101                 #region Properties
102
103                 public int LineNumber {
104                         get { return lineNumber; }
105                 }
106
107                 public int LinePosition {
108                         get { return linePosition; }
109                 }
110
111 #if NET_2_0
112                 public string SourceUri {
113                         get { return sourceUri; }
114                 }
115 #endif
116
117                 public override string Message {
118                         get {
119                                 if (lineNumber == 0)
120                                         return base.Message;
121
122                                 return String.Format (CultureInfo.InvariantCulture, "{0} {3} Line {1}, position {2}.",
123                                                       base.Message, lineNumber, linePosition, sourceUri);
124                         }
125                 }
126
127                 #endregion
128
129                 #region Methods
130
131                 [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
132                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
133                 {
134                         base.GetObjectData (info, context);
135                         info.AddValue ("lineNumber", lineNumber);
136                         info.AddValue ("linePosition", linePosition);
137                         info.AddValue ("sourceUri", sourceUri);
138                 }
139
140                 #endregion
141         }
142 }