XmlException.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. public XmlException ()
  45. : base ()
  46. {
  47. }
  48. public XmlException (string message, Exception innerException)
  49. : base (message, innerException)
  50. {
  51. }
  52. protected XmlException (SerializationInfo info, StreamingContext context)
  53. : base (info, context)
  54. {
  55. this.lineNumber = info.GetInt32 ("lineNumber");
  56. this.linePosition = info.GetInt32 ("linePosition");
  57. this.sourceUri = info.GetString ("sourceUri");
  58. }
  59. public XmlException (string message)
  60. : base (message)
  61. {
  62. }
  63. internal XmlException (IXmlLineInfo li,
  64. string sourceUri,
  65. string message)
  66. : this (li, null, sourceUri, message)
  67. {
  68. }
  69. internal XmlException (IXmlLineInfo li,
  70. Exception innerException,
  71. string sourceUri,
  72. string message)
  73. : base (message, innerException)
  74. {
  75. if (li != null) {
  76. this.lineNumber = li.LineNumber;
  77. this.linePosition = li.LinePosition;
  78. }
  79. this.sourceUri = sourceUri;
  80. }
  81. public XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  82. : base (message, innerException)
  83. {
  84. this.lineNumber = lineNumber;
  85. this.linePosition = linePosition;
  86. }
  87. #endregion
  88. #region Properties
  89. public int LineNumber {
  90. get { return lineNumber; }
  91. }
  92. public int LinePosition {
  93. get { return linePosition; }
  94. }
  95. #if NET_2_0
  96. public string SourceUri {
  97. get { return sourceUri; }
  98. }
  99. #endif
  100. public override string Message {
  101. get {
  102. if (lineNumber == 0)
  103. return base.Message;
  104. return String.Format (CultureInfo.InvariantCulture, "{0} {3} Line {1}, position {2}.",
  105. base.Message, lineNumber, linePosition, sourceUri);
  106. }
  107. }
  108. #endregion
  109. #region Methods
  110. [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
  111. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  112. {
  113. base.GetObjectData (info, context);
  114. info.AddValue ("lineNumber", lineNumber);
  115. info.AddValue ("linePosition", linePosition);
  116. info.AddValue ("sourceUri", sourceUri);
  117. }
  118. #endregion
  119. }
  120. }