NMSException.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. using System;
  18. namespace Apache.NMS
  19. {
  20. /// <summary>
  21. /// Represents an NMS exception
  22. /// </summary>
  23. [Serializable]
  24. public class NMSException : Exception
  25. {
  26. protected string exceptionErrorCode;
  27. public NMSException()
  28. : base()
  29. {
  30. }
  31. public NMSException(string message)
  32. : base(message)
  33. {
  34. }
  35. public NMSException(string message, string errorCode)
  36. : this(message)
  37. {
  38. exceptionErrorCode = errorCode;
  39. }
  40. public NMSException(string message, Exception innerException)
  41. : base(message, innerException)
  42. {
  43. }
  44. public NMSException(string message, string errorCode, Exception innerException)
  45. : base(message, innerException)
  46. {
  47. exceptionErrorCode = errorCode;
  48. }
  49. #region ISerializable interface implementation
  50. #if !NETCF
  51. /// <summary>
  52. /// Initializes a new instance of the NMSException class with serialized data.
  53. /// Throws System.ArgumentNullException if the info parameter is null.
  54. /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0).
  55. /// </summary>
  56. /// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thrown.</param>
  57. /// <param name="context">The StreamingContext that contains contextual information about the source or destination.</param>
  58. protected NMSException(System.Runtime.Serialization.SerializationInfo info,
  59. System.Runtime.Serialization.StreamingContext context)
  60. : base(info, context)
  61. {
  62. exceptionErrorCode = info.GetString("NMSException.exceptionErrorCode");
  63. }
  64. /// <summary>
  65. /// When overridden in a derived class, sets the SerializationInfo with information about the exception.
  66. /// </summary>
  67. /// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thrown.</param>
  68. /// <param name="context">The StreamingContext that contains contextual information about the source or destination.</param>
  69. public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info,
  70. System.Runtime.Serialization.StreamingContext context)
  71. {
  72. base.GetObjectData(info, context);
  73. info.AddValue("NMSException.exceptionErrorCode", exceptionErrorCode);
  74. }
  75. #endif
  76. #endregion
  77. /// <summary>
  78. /// Returns the error code for the exception, if one has been provided.
  79. /// </summary>
  80. public string ErrorCode
  81. {
  82. get { return exceptionErrorCode; }
  83. }
  84. }
  85. }