2 // System.Configuration.ConfigurationException.cs
5 // Duncan Mak (duncan@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System
.Globalization
;
33 using System
.Runtime
.Serialization
;
39 namespace System
.Configuration
42 public class ConfigurationException
: SystemException
45 readonly string filename
;
51 [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
52 public ConfigurationException () : this (null)
58 [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
59 public ConfigurationException (string message
)
64 protected ConfigurationException (SerializationInfo info
, StreamingContext context
)
65 : base (info
, context
)
67 filename
= info
.GetString ("filename");
68 line
= info
.GetInt32 ("line");
71 [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
72 public ConfigurationException (string message
, Exception inner
)
73 : base (message
, inner
)
78 [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
79 public ConfigurationException (string message
, XmlNode node
)
82 filename
= GetXmlNodeFilename(node
);
83 line
= GetXmlNodeLineNumber(node
);
86 [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
87 public ConfigurationException (string message
, Exception inner
, XmlNode node
)
88 : base (message
, inner
)
90 filename
= GetXmlNodeFilename (node
);
91 line
= GetXmlNodeLineNumber (node
);
94 [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
95 public ConfigurationException (string message
, string filename
, int line
)
98 this.filename
= filename
;
102 [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
103 public ConfigurationException (string message
, Exception inner
, string filename
, int line
)
104 : base (message
, inner
)
106 this.filename
= filename
;
112 public virtual string BareMessage
{
113 get { return base.Message; }
116 public virtual string Filename
{
117 get { return filename; }
120 public virtual int Line
{
124 public override string Message
{
127 if (filename
!= null && filename
.Length
!= 0) {
129 msg
= BareMessage
+ " (" + filename
+ " line " + line
+ ")";
131 msg
= BareMessage
+ " (" + filename
+ ")";
134 msg
= BareMessage
+ " (line " + line
+ ")";
146 [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
147 public static string GetXmlNodeFilename (XmlNode node
)
149 if (!(node
is IConfigXmlNode
))
152 return ((IConfigXmlNode
) node
).Filename
;
155 [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
156 public static int GetXmlNodeLineNumber (XmlNode node
)
158 if (!(node
is IConfigXmlNode
))
161 return ((IConfigXmlNode
) node
).LineNumber
;
164 public override void GetObjectData (SerializationInfo info
, StreamingContext context
)
166 base.GetObjectData (info
, context
);
167 info
.AddValue ("filename", filename
);
168 info
.AddValue ("line", line
);