XmlException.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. // (C) 2004 Novell Inc.
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Globalization;
  33. using System.Runtime.Serialization;
  34. using System.Security.Permissions;
  35. namespace System.Xml
  36. {
  37. [Serializable]
  38. public class XmlException : SystemException
  39. {
  40. #region Fields
  41. int lineNumber;
  42. int linePosition;
  43. string sourceUri;
  44. #endregion
  45. #region Constructors
  46. #if NET_1_0
  47. #else
  48. public XmlException ()
  49. : base ()
  50. {
  51. }
  52. #endif
  53. public XmlException (string message, Exception innerException)
  54. : base (message, innerException)
  55. {
  56. }
  57. protected XmlException (SerializationInfo info, StreamingContext context)
  58. : base (info, context)
  59. {
  60. this.lineNumber = info.GetInt32 ("lineNumber");
  61. this.linePosition = info.GetInt32 ("linePosition");
  62. this.sourceUri = info.GetString ("sourceUri");
  63. }
  64. #if NET_1_0
  65. internal XmlException (string message)
  66. #else
  67. public XmlException (string message)
  68. #endif
  69. : base (message)
  70. {
  71. }
  72. internal XmlException (IXmlLineInfo li, string sourceUri, string message) : base (message)
  73. {
  74. if (li != null) {
  75. this.lineNumber = li.LineNumber;
  76. this.linePosition = li.LinePosition;
  77. }
  78. this.sourceUri = sourceUri;
  79. }
  80. #if NET_1_0
  81. internal XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  82. #else
  83. public XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  84. #endif
  85. : base (message, innerException)
  86. {
  87. this.lineNumber = lineNumber;
  88. this.linePosition = linePosition;
  89. }
  90. #endregion
  91. #region Properties
  92. public int LineNumber {
  93. get { return lineNumber; }
  94. }
  95. public int LinePosition {
  96. get { return linePosition; }
  97. }
  98. #if NET_2_0
  99. public string SourceUri {
  100. get { return sourceUri; }
  101. }
  102. #endif
  103. public override string Message {
  104. get {
  105. if (lineNumber == 0)
  106. return base.Message;
  107. return String.Format (CultureInfo.InvariantCulture, "{0} {3} Line {1}, position {2}.",
  108. base.Message, lineNumber, linePosition, sourceUri);
  109. }
  110. }
  111. #endregion
  112. #region Methods
  113. #if NET_2_0
  114. [SecurityPermission (SecurityAction.LinkDemand,
  115. Flags=SecurityPermissionFlag.SerializationFormatter)]
  116. #endif
  117. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  118. {
  119. base.GetObjectData (info, context);
  120. info.AddValue ("lineNumber", lineNumber);
  121. info.AddValue ("linePosition", linePosition);
  122. info.AddValue ("sourceUri", sourceUri);
  123. }
  124. #endregion
  125. }
  126. }