ConfigurationException.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. public ConfigurationException ()
  48. : base (Locale.GetText ("There is an error in a configuration setting."))
  49. {
  50. filename = null;
  51. bareMessage = Locale.GetText ("There is an error in a configuration setting.");
  52. line = 0;
  53. }
  54. public ConfigurationException (string message)
  55. : base (message)
  56. {
  57. bareMessage = message;
  58. }
  59. protected ConfigurationException (SerializationInfo info, StreamingContext context)
  60. : base (info, context)
  61. {
  62. filename = info.GetString ("filename");
  63. line = info.GetInt32 ("line");
  64. }
  65. public ConfigurationException (string message, Exception inner)
  66. : base (message, inner)
  67. {
  68. bareMessage = message;
  69. }
  70. #if (XML_DEP)
  71. public ConfigurationException (string message, XmlNode node)
  72. : base (message)
  73. {
  74. filename = GetXmlNodeFilename(node);
  75. line = GetXmlNodeLineNumber(node);
  76. bareMessage = message;
  77. }
  78. public ConfigurationException (string message, Exception inner, XmlNode node)
  79. : base (message, inner)
  80. {
  81. filename = GetXmlNodeFilename (node);
  82. line = GetXmlNodeLineNumber (node);
  83. bareMessage = message;
  84. }
  85. #endif
  86. public ConfigurationException (string message, string filename, int line)
  87. : base (message)
  88. {
  89. bareMessage = message;
  90. this.filename = filename;
  91. this.line= line;
  92. }
  93. public ConfigurationException (string message, Exception inner, string filename, int line)
  94. : base (message)
  95. {
  96. bareMessage = message;
  97. this.filename = filename;
  98. this.line = line;
  99. }
  100. //
  101. // Properties
  102. //
  103. public string BareMessage
  104. {
  105. get { return bareMessage; }
  106. }
  107. public string Filename
  108. {
  109. get { return filename; }
  110. }
  111. public int Line
  112. {
  113. get { return line; }
  114. }
  115. public override string Message
  116. {
  117. get {
  118. string baseMsg = base.Message;
  119. string f = (filename == null) ? String.Empty : filename;
  120. string l = (line == 0) ? String.Empty : (" line " + line);
  121. return baseMsg + " (" + f + l + ")";
  122. }
  123. }
  124. //
  125. // Methods
  126. //
  127. #if (XML_DEP)
  128. public static string GetXmlNodeFilename (XmlNode node)
  129. {
  130. if (!(node is IConfigXmlNode))
  131. return String.Empty;
  132. return ((IConfigXmlNode) node).Filename;
  133. }
  134. public static int GetXmlNodeLineNumber (XmlNode node)
  135. {
  136. if (!(node is IConfigXmlNode))
  137. return 0;
  138. return ((IConfigXmlNode) node).LineNumber;
  139. }
  140. #endif
  141. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  142. {
  143. base.GetObjectData (info, context);
  144. info.AddValue ("filename", filename);
  145. info.AddValue ("line", line);
  146. }
  147. }
  148. }