ConfigurationException.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //
  2. // System.Configuration.ConfigurationException.cs
  3. //
  4. // Author:
  5. // Duncan Mak ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Globalization;
  31. using System.Runtime.Serialization;
  32. #if (XML_DEP)
  33. using System.Xml;
  34. #endif
  35. namespace System.Configuration
  36. {
  37. [Serializable]
  38. public class ConfigurationException : SystemException
  39. {
  40. // Fields
  41. string bareMessage;
  42. string filename;
  43. int line;
  44. //
  45. // Constructors
  46. //
  47. #if NET_2_0
  48. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  49. #endif
  50. public ConfigurationException ()
  51. : base (Locale.GetText ("There is an error in a configuration setting."))
  52. {
  53. filename = null;
  54. bareMessage = Locale.GetText ("There is an error in a configuration setting.");
  55. line = 0;
  56. }
  57. #if NET_2_0
  58. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  59. #endif
  60. public ConfigurationException (string message)
  61. : base (message)
  62. {
  63. bareMessage = message;
  64. }
  65. protected ConfigurationException (SerializationInfo info, StreamingContext context)
  66. : base (info, context)
  67. {
  68. filename = info.GetString ("filename");
  69. line = info.GetInt32 ("line");
  70. }
  71. #if NET_2_0
  72. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  73. #endif
  74. public ConfigurationException (string message, Exception inner)
  75. : base (message, inner)
  76. {
  77. bareMessage = message;
  78. }
  79. #if (XML_DEP)
  80. #if NET_2_0
  81. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  82. #endif
  83. public ConfigurationException (string message, XmlNode node)
  84. : base (message)
  85. {
  86. filename = GetXmlNodeFilename(node);
  87. line = GetXmlNodeLineNumber(node);
  88. bareMessage = message;
  89. }
  90. #if NET_2_0
  91. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  92. #endif
  93. public ConfigurationException (string message, Exception inner, XmlNode node)
  94. : base (message, inner)
  95. {
  96. filename = GetXmlNodeFilename (node);
  97. line = GetXmlNodeLineNumber (node);
  98. bareMessage = message;
  99. }
  100. #endif
  101. #if NET_2_0
  102. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  103. #endif
  104. public ConfigurationException (string message, string filename, int line)
  105. : base (message)
  106. {
  107. bareMessage = message;
  108. this.filename = filename;
  109. this.line= line;
  110. }
  111. #if NET_2_0
  112. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  113. #endif
  114. public ConfigurationException (string message, Exception inner, string filename, int line)
  115. : base (message)
  116. {
  117. bareMessage = message;
  118. this.filename = filename;
  119. this.line = line;
  120. }
  121. //
  122. // Properties
  123. //
  124. public string BareMessage
  125. {
  126. get { return bareMessage; }
  127. }
  128. public string Filename
  129. {
  130. get { return filename; }
  131. }
  132. public int Line
  133. {
  134. get { return line; }
  135. }
  136. public override string Message
  137. {
  138. get {
  139. string baseMsg = base.Message;
  140. string f = (filename == null) ? String.Empty : filename;
  141. string l = (line == 0) ? String.Empty : (" line " + line);
  142. return baseMsg + " (" + f + l + ")";
  143. }
  144. }
  145. //
  146. // Methods
  147. //
  148. #if (XML_DEP)
  149. #if NET_2_0
  150. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  151. #endif
  152. public static string GetXmlNodeFilename (XmlNode node)
  153. {
  154. if (!(node is IConfigXmlNode))
  155. return String.Empty;
  156. return ((IConfigXmlNode) node).Filename;
  157. }
  158. #if NET_2_0
  159. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  160. #endif
  161. public static int GetXmlNodeLineNumber (XmlNode node)
  162. {
  163. if (!(node is IConfigXmlNode))
  164. return 0;
  165. return ((IConfigXmlNode) node).LineNumber;
  166. }
  167. #endif
  168. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  169. {
  170. base.GetObjectData (info, context);
  171. info.AddValue ("filename", filename);
  172. info.AddValue ("line", line);
  173. }
  174. }
  175. }