mscorlib(4.0.0.0) API with additions
WebSocketException.cs
5 
6 namespace System.Net.WebSockets
7 {
10  public sealed class WebSocketException : Win32Exception
11  {
12  private WebSocketError m_WebSocketErrorCode;
13 
16  public override int ErrorCode => base.NativeErrorCode;
17 
20  public WebSocketError WebSocketErrorCode => m_WebSocketErrorCode;
21 
24  : this(Marshal.GetLastWin32Error())
25  {
26  }
27 
31  : this(error, GetErrorMessage(error))
32  {
33  }
34 
38  public WebSocketException(WebSocketError error, string message)
39  : base(message)
40  {
41  m_WebSocketErrorCode = error;
42  }
43 
47  public WebSocketException(WebSocketError error, Exception innerException)
48  : this(error, GetErrorMessage(error), innerException)
49  {
50  }
51 
56  public WebSocketException(WebSocketError error, string message, Exception innerException)
57  : base(message, innerException)
58  {
59  m_WebSocketErrorCode = error;
60  }
61 
64  public WebSocketException(int nativeError)
65  : base(nativeError)
66  {
67  m_WebSocketErrorCode = ((!WebSocketProtocolComponent.Succeeded(nativeError)) ? WebSocketError.NativeError : WebSocketError.Success);
68  SetErrorCodeOnError(nativeError);
69  }
70 
74  public WebSocketException(int nativeError, string message)
75  : base(nativeError, message)
76  {
77  m_WebSocketErrorCode = ((!WebSocketProtocolComponent.Succeeded(nativeError)) ? WebSocketError.NativeError : WebSocketError.Success);
78  SetErrorCodeOnError(nativeError);
79  }
80 
84  public WebSocketException(int nativeError, Exception innerException)
85  : base(SR.GetString("net_WebSockets_Generic"), innerException)
86  {
87  m_WebSocketErrorCode = ((!WebSocketProtocolComponent.Succeeded(nativeError)) ? WebSocketError.NativeError : WebSocketError.Success);
88  SetErrorCodeOnError(nativeError);
89  }
90 
94  public WebSocketException(WebSocketError error, int nativeError)
95  : this(error, nativeError, GetErrorMessage(error))
96  {
97  }
98 
103  public WebSocketException(WebSocketError error, int nativeError, string message)
104  : base(message)
105  {
106  m_WebSocketErrorCode = error;
107  SetErrorCodeOnError(nativeError);
108  }
109 
114  public WebSocketException(WebSocketError error, int nativeError, Exception innerException)
115  : this(error, nativeError, GetErrorMessage(error), innerException)
116  {
117  }
118 
124  public WebSocketException(WebSocketError error, int nativeError, string message, Exception innerException)
125  : base(message, innerException)
126  {
127  m_WebSocketErrorCode = error;
128  SetErrorCodeOnError(nativeError);
129  }
130 
133  public WebSocketException(string message)
134  : base(message)
135  {
136  }
137 
141  public WebSocketException(string message, Exception innerException)
142  : base(message, innerException)
143  {
144  }
145 
146  private WebSocketException(SerializationInfo serializationInfo, StreamingContext streamingContext)
147  : base(serializationInfo, streamingContext)
148  {
149  }
150 
151  private static string GetErrorMessage(WebSocketError error)
152  {
153  switch (error)
154  {
155  case WebSocketError.InvalidMessageType:
156  return SR.GetString("net_WebSockets_InvalidMessageType_Generic", typeof(WebSocket).Name + "CloseAsync", typeof(WebSocket).Name + "CloseOutputAsync");
157  case WebSocketError.Faulted:
158  return SR.GetString("net_Websockets_WebSocketBaseFaulted");
159  case WebSocketError.NotAWebSocket:
160  return SR.GetString("net_WebSockets_NotAWebSocket_Generic");
161  case WebSocketError.UnsupportedVersion:
162  return SR.GetString("net_WebSockets_UnsupportedWebSocketVersion_Generic");
163  case WebSocketError.UnsupportedProtocol:
164  return SR.GetString("net_WebSockets_UnsupportedProtocol_Generic");
165  case WebSocketError.HeaderError:
166  return SR.GetString("net_WebSockets_HeaderError_Generic");
167  case WebSocketError.ConnectionClosedPrematurely:
168  return SR.GetString("net_WebSockets_ConnectionClosedPrematurely_Generic");
169  case WebSocketError.InvalidState:
170  return SR.GetString("net_WebSockets_InvalidState_Generic");
171  default:
172  return SR.GetString("net_WebSockets_Generic");
173  }
174  }
175 
179  [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
180  public override void GetObjectData(SerializationInfo info, StreamingContext context)
181  {
182  if (info == null)
183  {
184  throw new ArgumentNullException("info");
185  }
186  info.AddValue("WebSocketErrorCode", m_WebSocketErrorCode);
187  base.GetObjectData(info, context);
188  }
189 
190  private void SetErrorCodeOnError(int nativeError)
191  {
192  if (!WebSocketProtocolComponent.Succeeded(nativeError))
193  {
194  base.HResult = nativeError;
195  }
196  }
197  }
198 }
WebSocketException(int nativeError, string message)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
override void GetObjectData(SerializationInfo info, StreamingContext context)
Sets the SerializationInfo object with the file name and line number where the exception occurred.
override int ErrorCode
The native error code for the exception that occurred.
WebSocketException(string message, Exception innerException)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
Definition: __Canon.cs:3
WebSocketException(WebSocketError error, string message, Exception innerException)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
WebSocketException(WebSocketError error, int nativeError)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
WebSocketError WebSocketErrorCode
Returns a WebSocketError indicating the type of error that occurred.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Throws an exception for a Win32 error code.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
WebSocketException(int nativeError)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
WebSocketException(WebSocketError error, Exception innerException)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
WebSocketException(string message)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
WebSocketException()
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
WebSocketException(WebSocketError error, int nativeError, string message)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
Represents an exception that occurred when performing an operation on a WebSocket connection.
WebSocketError
Contains the list of possible WebSocket errors.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
WebSocketException(WebSocketError error, int nativeError, string message, Exception innerException)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
WebSocketException(int nativeError, Exception innerException)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
WebSocketException(WebSocketError error, int nativeError, Exception innerException)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
Specifies that the class can be serialized.
WebSocketException(WebSocketError error, string message)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.
WebSocketException(WebSocketError error)
Creates an instance of the T:System.Net.WebSockets.WebSocketException class.