XmlException.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // XmlException.cs
  3. //
  4. // Author:
  5. // Jason Diamond ([email protected])
  6. //
  7. // (C) 2002 Jason Diamond http://injektilo.org/
  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. namespace System.Xml
  33. {
  34. [Serializable]
  35. public class XmlException : SystemException
  36. {
  37. #region Fields
  38. int lineNumber;
  39. int linePosition;
  40. #endregion
  41. #region Constructors
  42. #if NET_1_0
  43. #else
  44. public XmlException ()
  45. : base ()
  46. {
  47. }
  48. #endif
  49. public XmlException (string message, Exception innerException)
  50. : base (message, innerException)
  51. {
  52. }
  53. protected XmlException (SerializationInfo info, StreamingContext context)
  54. : base (info, context)
  55. {
  56. this.lineNumber = info.GetInt32 ("lineNumber");
  57. this.linePosition = info.GetInt32 ("linePosition");
  58. }
  59. #if NET_1_0
  60. internal XmlException (string message)
  61. #else
  62. public XmlException (string message)
  63. #endif
  64. : base (message)
  65. {
  66. }
  67. internal XmlException (IXmlLineInfo li, string message) : base (message)
  68. {
  69. if (li != null) {
  70. this.lineNumber = li.LineNumber;
  71. this.linePosition = li.LinePosition;
  72. }
  73. }
  74. #if NET_1_0
  75. internal XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  76. #else
  77. public XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  78. #endif
  79. : base (message, innerException)
  80. {
  81. this.lineNumber = lineNumber;
  82. this.linePosition = linePosition;
  83. }
  84. #endregion
  85. #region Properties
  86. public int LineNumber {
  87. get { return lineNumber; }
  88. }
  89. public int LinePosition {
  90. get { return linePosition; }
  91. }
  92. public override string Message {
  93. get {
  94. if (lineNumber == 0)
  95. return base.Message;
  96. return String.Format (CultureInfo.InvariantCulture, "{0} Line {1}, position {2}.",
  97. base.Message, lineNumber, linePosition);
  98. }
  99. }
  100. #endregion
  101. #region Methods
  102. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  103. {
  104. base.GetObjectData (info, context);
  105. info.AddValue ("lineNumber", lineNumber);
  106. info.AddValue ("linePosition", linePosition);
  107. }
  108. #endregion
  109. }
  110. }