Skip to content

Commit 4cc4837

Browse files
committed
[Modify] Throw exceptions
1 parent d13d4c8 commit 4cc4837

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

websocket-sharp/WebSocket.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,17 +2848,19 @@ public void SendAsync (FileInfo file, Action<bool> completed)
28482848
/// </param>
28492849
public void SendAsync (string data, Action<bool> completed)
28502850
{
2851-
var msg = _readyState.CheckIfAvailable (false, true, false, false) ??
2852-
CheckSendParameter (data);
2851+
if (_readyState != WebSocketState.Open) {
2852+
var msg = "The current state of the connection is not Open.";
2853+
throw new InvalidOperationException (msg);
2854+
}
28532855

2854-
if (msg != null) {
2855-
_logger.Error (msg);
2856-
error ("An error has occurred in sending data.", null);
2856+
if (data == null)
2857+
throw new ArgumentNullException ("data");
28572858

2858-
return;
2859-
}
2859+
byte[] bytes;
2860+
if (!data.TryGetUTF8EncodedBytes (out bytes))
2861+
throw new ArgumentException ("Cannot be UTF8 encoded.", "data");
28602862

2861-
sendAsync (Opcode.Text, new MemoryStream (data.UTF8Encode ()), completed);
2863+
sendAsync (Opcode.Text, new MemoryStream (bytes), completed);
28622864
}
28632865

28642866
/// <summary>

0 commit comments

Comments
 (0)