New test.
[mono.git] / mcs / class / System / System.Configuration / ConfigurationException.cs
1 //
2 // System.Configuration.ConfigurationException.cs
3 //
4 // Author:
5 //   Duncan Mak (duncan@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
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;
32 using System.Globalization;
33 using System.Runtime.Serialization;
34
35 #if (XML_DEP)
36 using System.Xml;
37 #endif
38
39 namespace System.Configuration 
40 {
41         [Serializable]
42         public class ConfigurationException : SystemException
43         {
44                 // Fields               
45                 string bareMessage;
46                 string filename;
47                 int line;
48
49                 //
50                 // Constructors
51                 //
52 #if NET_2_0
53                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
54 #endif
55                 public ConfigurationException ()
56                         : base (Locale.GetText ("There is an error in a configuration setting."))
57                 {
58                         filename = null;
59                         bareMessage = Locale.GetText ("There is an error in a configuration setting.");
60                         line = 0;
61                 }
62
63 #if NET_2_0
64                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
65 #endif
66                 public ConfigurationException (string message)
67                         : base (message)
68                 {
69                         bareMessage = message;
70                 }
71
72                 protected ConfigurationException (SerializationInfo info, StreamingContext context)
73                         : base (info, context)
74                 {
75                         filename = info.GetString ("filename");
76                         line = info.GetInt32 ("line");
77                 }
78
79 #if NET_2_0
80                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
81 #endif
82                 public ConfigurationException (string message, Exception inner)
83                         : base (message, inner)
84                 {
85                         bareMessage = message;
86                 }
87
88 #if (XML_DEP)
89 #if NET_2_0
90                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
91 #endif
92                 public ConfigurationException (string message, XmlNode node)
93                         : base (message)
94                 {
95                         filename = GetXmlNodeFilename(node);
96                         line = GetXmlNodeLineNumber(node);
97                         bareMessage = message;
98                 }
99
100 #if NET_2_0
101                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
102 #endif
103                 public ConfigurationException (string message, Exception inner, XmlNode node)
104                         : base (message, inner)
105                 {
106                         filename = GetXmlNodeFilename (node);
107                         line = GetXmlNodeLineNumber (node);
108                         bareMessage = message;
109                 }
110 #endif
111 #if NET_2_0
112                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
113 #endif
114                 public ConfigurationException (string message, string filename, int line)
115                         : base (message)
116                 {
117                         bareMessage = message;
118                         this.filename = filename;
119                         this.line= line;
120                 }
121
122 #if NET_2_0
123                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
124 #endif
125                 public ConfigurationException (string message, Exception inner, string filename, int line)
126                         : base (message)
127                 {
128                         bareMessage = message;
129                         this.filename = filename;
130                         this.line = line;
131                 }
132                 //
133                 // Properties
134                 //
135                 public
136 #if NET_2_0
137                 virtual
138 #endif
139                 string BareMessage
140                 {
141                         get  { return bareMessage; }
142                 }
143
144                 public
145 #if NET_2_0
146                 virtual
147 #endif
148                 string Filename
149                 {
150                         get { return filename; }
151                 }
152
153                 public  
154 #if NET_2_0
155                 virtual
156 #endif
157                 int Line
158                 {
159                         get { return line; }
160                 }
161
162                 public override string Message
163                 {
164                         get {
165                                 string baseMsg = base.Message;
166                                 string f = (filename == null) ? String.Empty : filename;
167                                 string l = (line == 0) ? String.Empty : (" line " + line);
168
169                                 return baseMsg + " (" + f + l + ")";
170                         }
171                 }
172
173                 //
174                 // Methods
175                 //
176 #if (XML_DEP)
177 #if NET_2_0
178                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
179 #endif
180                 public static string GetXmlNodeFilename (XmlNode node)
181                 {
182                         if (!(node is IConfigXmlNode))
183                                 return String.Empty;
184
185                         return ((IConfigXmlNode) node).Filename;
186                 }
187
188 #if NET_2_0
189                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
190 #endif
191                 public static int GetXmlNodeLineNumber (XmlNode node)
192                 {
193                         if (!(node is IConfigXmlNode))
194                                 return 0;
195
196                         return ((IConfigXmlNode) node).LineNumber;
197                 }
198 #endif
199                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
200                 {
201                         base.GetObjectData (info, context);
202                         info.AddValue ("filename", filename);
203                         info.AddValue ("line", line);
204                 }
205         }
206 }