WebSocketException.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #region License
  2. /*
  3. * WebSocketException.cs
  4. *
  5. * The MIT License
  6. *
  7. * Copyright (c) 2012-2022 sta.blockhead
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. */
  27. #endregion
  28. using System;
  29. namespace WebSocketSharp
  30. {
  31. /// <summary>
  32. /// The exception that is thrown when a fatal error occurs in
  33. /// the WebSocket communication.
  34. /// </summary>
  35. public class WebSocketException : Exception
  36. {
  37. #region Private Fields
  38. private ushort _code;
  39. #endregion
  40. #region Private Constructors
  41. private WebSocketException (
  42. ushort code, string message, Exception innerException
  43. )
  44. : base (message ?? code.GetErrorMessage (), innerException)
  45. {
  46. _code = code;
  47. }
  48. #endregion
  49. #region Internal Constructors
  50. internal WebSocketException ()
  51. : this (CloseStatusCode.Abnormal, null, null)
  52. {
  53. }
  54. internal WebSocketException (Exception innerException)
  55. : this (CloseStatusCode.Abnormal, null, innerException)
  56. {
  57. }
  58. internal WebSocketException (string message)
  59. : this (CloseStatusCode.Abnormal, message, null)
  60. {
  61. }
  62. internal WebSocketException (CloseStatusCode code)
  63. : this (code, null, null)
  64. {
  65. }
  66. internal WebSocketException (string message, Exception innerException)
  67. : this (CloseStatusCode.Abnormal, message, innerException)
  68. {
  69. }
  70. internal WebSocketException (CloseStatusCode code, Exception innerException)
  71. : this (code, null, innerException)
  72. {
  73. }
  74. internal WebSocketException (CloseStatusCode code, string message)
  75. : this (code, message, null)
  76. {
  77. }
  78. internal WebSocketException (
  79. CloseStatusCode code, string message, Exception innerException
  80. )
  81. : this ((ushort) code, message, innerException)
  82. {
  83. }
  84. #endregion
  85. #region Public Properties
  86. /// <summary>
  87. /// Gets the status code indicating the cause of the exception.
  88. /// </summary>
  89. /// <value>
  90. /// <para>
  91. /// A <see cref="ushort"/> that represents the status code indicating
  92. /// the cause of the exception.
  93. /// </para>
  94. /// <para>
  95. /// It is one of the status codes for the WebSocket connection close.
  96. /// </para>
  97. /// </value>
  98. public ushort Code {
  99. get {
  100. return _code;
  101. }
  102. }
  103. #endregion
  104. }
  105. }