XmlException.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // XmlException.cs
  3. //
  4. // Author:
  5. // Jason Diamond ([email protected])
  6. // Atsushi Enomoto ([email protected])
  7. //
  8. // (C) 2002 Jason Diamond http://injektilo.org/
  9. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  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. using System.Globalization;
  31. using System.Runtime.Serialization;
  32. using System.Security.Permissions;
  33. namespace System.Xml
  34. {
  35. [Serializable]
  36. public class XmlException : SystemException
  37. {
  38. #region Fields
  39. int lineNumber;
  40. int linePosition;
  41. string sourceUri;
  42. #endregion
  43. #region Constructors
  44. #if NET_1_0
  45. #else
  46. public XmlException ()
  47. : base ()
  48. {
  49. }
  50. #endif
  51. public XmlException (string message, Exception innerException)
  52. : base (message, innerException)
  53. {
  54. }
  55. protected XmlException (SerializationInfo info, StreamingContext context)
  56. : base (info, context)
  57. {
  58. this.lineNumber = info.GetInt32 ("lineNumber");
  59. this.linePosition = info.GetInt32 ("linePosition");
  60. this.sourceUri = info.GetString ("sourceUri");
  61. }
  62. #if NET_1_0
  63. internal XmlException (string message)
  64. #else
  65. public XmlException (string message)
  66. #endif
  67. : base (message)
  68. {
  69. }
  70. internal XmlException (IXmlLineInfo li,
  71. string sourceUri,
  72. string message)
  73. : this (li, null, sourceUri, message)
  74. {
  75. }
  76. internal XmlException (IXmlLineInfo li,
  77. Exception innerException,
  78. string sourceUri,
  79. string message)
  80. : base (message, innerException)
  81. {
  82. if (li != null) {
  83. this.lineNumber = li.LineNumber;
  84. this.linePosition = li.LinePosition;
  85. }
  86. this.sourceUri = sourceUri;
  87. }
  88. #if NET_1_0
  89. internal XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  90. #else
  91. public XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  92. #endif
  93. : base (message, innerException)
  94. {
  95. this.lineNumber = lineNumber;
  96. this.linePosition = linePosition;
  97. }
  98. #endregion
  99. #region Properties
  100. public int LineNumber {
  101. get { return lineNumber; }
  102. }
  103. public int LinePosition {
  104. get { return linePosition; }
  105. }
  106. #if NET_2_0
  107. public string SourceUri {
  108. get { return sourceUri; }
  109. }
  110. #endif
  111. public override string Message {
  112. get {
  113. if (lineNumber == 0)
  114. return base.Message;
  115. return String.Format (CultureInfo.InvariantCulture, "{0} {3} Line {1}, position {2}.",
  116. base.Message, lineNumber, linePosition, sourceUri);
  117. }
  118. }
  119. #endregion
  120. #region Methods
  121. [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
  122. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  123. {
  124. base.GetObjectData (info, context);
  125. info.AddValue ("lineNumber", lineNumber);
  126. info.AddValue ("linePosition", linePosition);
  127. info.AddValue ("sourceUri", sourceUri);
  128. }
  129. #endregion
  130. }
  131. }