ConfigurationException.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. readonly string filename;
  42. readonly int line;
  43. //
  44. // Constructors
  45. //
  46. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  47. public ConfigurationException () : this (null)
  48. {
  49. filename = null;
  50. line = 0;
  51. }
  52. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  53. public ConfigurationException (string message)
  54. : base (message)
  55. {
  56. }
  57. protected ConfigurationException (SerializationInfo info, StreamingContext context)
  58. : base (info, context)
  59. {
  60. filename = info.GetString ("filename");
  61. line = info.GetInt32 ("line");
  62. }
  63. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  64. public ConfigurationException (string message, Exception inner)
  65. : base (message, inner)
  66. {
  67. }
  68. #if (XML_DEP)
  69. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  70. public ConfigurationException (string message, XmlNode node)
  71. : base (message)
  72. {
  73. filename = GetXmlNodeFilename(node);
  74. line = GetXmlNodeLineNumber(node);
  75. }
  76. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  77. public ConfigurationException (string message, Exception inner, XmlNode node)
  78. : base (message, inner)
  79. {
  80. filename = GetXmlNodeFilename (node);
  81. line = GetXmlNodeLineNumber (node);
  82. }
  83. #endif
  84. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  85. public ConfigurationException (string message, string filename, int line)
  86. : base (message)
  87. {
  88. this.filename = filename;
  89. this.line= line;
  90. }
  91. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  92. public ConfigurationException (string message, Exception inner, string filename, int line)
  93. : base (message, inner)
  94. {
  95. this.filename = filename;
  96. this.line = line;
  97. }
  98. //
  99. // Properties
  100. //
  101. public virtual string BareMessage {
  102. get { return base.Message; }
  103. }
  104. public virtual string Filename {
  105. get { return filename; }
  106. }
  107. public virtual int Line {
  108. get { return line; }
  109. }
  110. public override string Message {
  111. get {
  112. string msg;
  113. if (filename != null && filename.Length != 0) {
  114. if (line != 0)
  115. msg = BareMessage + " (" + filename + " line " + line + ")";
  116. else
  117. msg = BareMessage + " (" + filename + ")";
  118. } else {
  119. if (line != 0)
  120. msg = BareMessage + " (line " + line + ")";
  121. else
  122. msg = BareMessage;
  123. }
  124. return msg;
  125. }
  126. }
  127. //
  128. // Methods
  129. //
  130. #if (XML_DEP)
  131. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  132. public static string GetXmlNodeFilename (XmlNode node)
  133. {
  134. if (!(node is IConfigXmlNode))
  135. return String.Empty;
  136. return ((IConfigXmlNode) node).Filename;
  137. }
  138. [Obsolete ("This class is obsolete. Use System.Configuration.ConfigurationErrorsException")]
  139. public static int GetXmlNodeLineNumber (XmlNode node)
  140. {
  141. if (!(node is IConfigXmlNode))
  142. return 0;
  143. return ((IConfigXmlNode) node).LineNumber;
  144. }
  145. #endif
  146. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  147. {
  148. base.GetObjectData (info, context);
  149. info.AddValue ("filename", filename);
  150. info.AddValue ("line", line);
  151. }
  152. }
  153. }