XmlException.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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, string sourceUri, string message) : base (message)
  71. {
  72. if (li != null) {
  73. this.lineNumber = li.LineNumber;
  74. this.linePosition = li.LinePosition;
  75. }
  76. this.sourceUri = sourceUri;
  77. }
  78. #if NET_1_0
  79. internal XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  80. #else
  81. public XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  82. #endif
  83. : base (message, innerException)
  84. {
  85. this.lineNumber = lineNumber;
  86. this.linePosition = linePosition;
  87. }
  88. #endregion
  89. #region Properties
  90. public int LineNumber {
  91. get { return lineNumber; }
  92. }
  93. public int LinePosition {
  94. get { return linePosition; }
  95. }
  96. #if NET_2_0
  97. public string SourceUri {
  98. get { return sourceUri; }
  99. }
  100. #endif
  101. public override string Message {
  102. get {
  103. if (lineNumber == 0)
  104. return base.Message;
  105. return String.Format (CultureInfo.InvariantCulture, "{0} {3} Line {1}, position {2}.",
  106. base.Message, lineNumber, linePosition, sourceUri);
  107. }
  108. }
  109. #endregion
  110. #region Methods
  111. [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
  112. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  113. {
  114. base.GetObjectData (info, context);
  115. info.AddValue ("lineNumber", lineNumber);
  116. info.AddValue ("linePosition", linePosition);
  117. info.AddValue ("sourceUri", sourceUri);
  118. }
  119. #endregion
  120. }
  121. }