*** empty log message ***
[mono.git] / mcs / class / System.XML / System.Xml / XmlException.cs
1 //
2 // XmlException.cs
3 //
4 // Author:
5 //   Jason Diamond (jason@injektilo.org)
6 //
7 // (C) 2002 Jason Diamond  http://injektilo.org/
8 //
9
10 using System;
11 using System.Runtime.Serialization;
12
13 namespace System.Xml
14 {
15         [Serializable]
16         public class XmlException : SystemException
17         {
18                 #region Fields
19
20                 int lineNumber;
21                 int linePosition;
22
23                 #endregion
24
25                 #region Constructors
26
27                 public XmlException (string message, Exception innerException) 
28                         : base (message, innerException)
29                 {
30                 }
31
32                 protected XmlException (SerializationInfo info, StreamingContext context)
33                         : base (info, context)
34                 {
35                         this.lineNumber = info.GetInt32 ("lineNumber");
36                         this.linePosition = info.GetInt32 ("linePosition");
37                 }
38
39                 internal XmlException (string message)
40                         : base (message)
41                 {
42                 }
43
44                 internal XmlException (IXmlLineInfo li, string message) : base (message)
45                 {
46                         if (li != null) {
47                                 this.lineNumber = li.LineNumber;
48                                 this.linePosition = li.LinePosition;
49                         }
50                 }
51                 
52                 internal XmlException (string message, int lineNumber, int linePosition) : base (message)
53                 {
54                         this.lineNumber = lineNumber;
55                         this.linePosition = linePosition;
56                 }
57
58                 #endregion
59
60                 #region Properties
61
62                 public int LineNumber {
63                         get { return lineNumber; }
64                 }
65
66                 public int LinePosition {
67                         get { return linePosition; }
68                 }
69
70                 public override string Message {
71                         get {
72                                 if (lineNumber == 0)
73                                         return base.Message;
74
75                                 return String.Format ("{0} Line {1}, position {2}.",
76                                                       base.Message, lineNumber, linePosition);
77                         }
78                 }
79
80                 #endregion
81
82                 #region Methods
83
84                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
85                 {
86                         base.GetObjectData (info, context);
87                         info.AddValue ("lineNumber", lineNumber);
88                         info.AddValue ("linePosition", linePosition);
89                 }
90
91                 #endregion
92         }
93 }