XmlException.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // XmlException.cs
  3. //
  4. // Author:
  5. // Jason Diamond ([email protected])
  6. //
  7. // (C) 2002 Jason Diamond http://injektilo.org/
  8. //
  9. using System;
  10. using System.Runtime.Serialization;
  11. namespace System.Xml
  12. {
  13. [Serializable]
  14. public class XmlException : SystemException
  15. {
  16. #region Fields
  17. int lineNumber;
  18. int linePosition;
  19. #endregion
  20. #region Constructors
  21. #if NET_1_0
  22. #else
  23. public XmlException ()
  24. : base ()
  25. {
  26. }
  27. #endif
  28. public XmlException (string message, Exception innerException)
  29. : base (message, innerException)
  30. {
  31. }
  32. protected XmlException (SerializationInfo info, StreamingContext context)
  33. : base (info, context)
  34. {
  35. this.lineNumber = info.GetInt32 ("lineNumber");
  36. this.linePosition = info.GetInt32 ("linePosition");
  37. }
  38. #if NET_1_0
  39. internal XmlException (string message)
  40. #else
  41. public XmlException (string message)
  42. #endif
  43. : base (message)
  44. {
  45. }
  46. internal XmlException (IXmlLineInfo li, string message) : base (message)
  47. {
  48. if (li != null) {
  49. this.lineNumber = li.LineNumber;
  50. this.linePosition = li.LinePosition;
  51. }
  52. }
  53. #if NET_1_0
  54. internal XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  55. #else
  56. public XmlException (string message, Exception innerException, int lineNumber, int linePosition)
  57. #endif
  58. : base (message, innerException)
  59. {
  60. this.lineNumber = lineNumber;
  61. this.linePosition = linePosition;
  62. }
  63. #endregion
  64. #region Properties
  65. public int LineNumber {
  66. get { return lineNumber; }
  67. }
  68. public int LinePosition {
  69. get { return linePosition; }
  70. }
  71. public override string Message {
  72. get {
  73. if (lineNumber == 0)
  74. return base.Message;
  75. return String.Format ("{0} Line {1}, position {2}.",
  76. base.Message, lineNumber, linePosition);
  77. }
  78. }
  79. #endregion
  80. #region Methods
  81. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  82. {
  83. base.GetObjectData (info, context);
  84. info.AddValue ("lineNumber", lineNumber);
  85. info.AddValue ("linePosition", linePosition);
  86. }
  87. #endregion
  88. }
  89. }