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
52 public ConfigurationException ()
53 : base (Locale.GetText ("There is an error in a configuration setting."))
56 bareMessage = Locale.GetText ("There is an error in a configuration setting.");
60 public ConfigurationException (string message)
63 bareMessage = message;
66 protected ConfigurationException (SerializationInfo info, StreamingContext context)
67 : base (info, context)
69 filename = info.GetString ("filename");
70 line = info.GetInt32 ("line");
73 public ConfigurationException (string message, Exception inner)
74 : base (message, inner)
76 bareMessage = message;
80 public ConfigurationException (string message, XmlNode node)
83 filename = GetXmlNodeFilename(node);
84 line = GetXmlNodeLineNumber(node);
85 bareMessage = message;
88 public ConfigurationException (string message, Exception inner, XmlNode node)
89 : base (message, inner)
91 filename = GetXmlNodeFilename (node);
92 line = GetXmlNodeLineNumber (node);
93 bareMessage = message;
96 public ConfigurationException (string message, string filename, int line)
99 bareMessage = message;
100 this.filename = filename;
104 public ConfigurationException (string message, Exception inner, string filename, int line)
107 bareMessage = message;
108 this.filename = filename;
114 public string BareMessage
116 get { return bareMessage; }
119 public string Filename
121 get { return filename; }
129 public override string Message
132 string baseMsg = base.Message;
133 string f = (filename == null) ? String.Empty : filename;
134 string l = (line == 0) ? String.Empty : (" line " + line);
136 return baseMsg + " (" + f + l + ")";
144 public static string GetXmlNodeFilename (XmlNode node)
146 if (!(node is IConfigXmlNode))
149 return ((IConfigXmlNode) node).Filename;
152 public static int GetXmlNodeLineNumber (XmlNode node)
154 if (!(node is IConfigXmlNode))
157 return ((IConfigXmlNode) node).LineNumber;
160 public override void GetObjectData (SerializationInfo info, StreamingContext context)
162 base.GetObjectData (info, context);
163 info.AddValue ("filename", filename);
164 info.AddValue ("line", line);