[Modify] Throw exceptions

This commit is contained in:
sta 2016-11-18 15:57:52 +09:00
parent 7e98434f6c
commit c13dbeb051

View File

@ -2722,17 +2722,19 @@ namespace WebSocketSharp
/// </param> /// </param>
public void Send (string data) public void Send (string data)
{ {
var msg = _readyState.CheckIfAvailable (false, true, false, false) ?? if (_readyState != WebSocketState.Open) {
CheckSendParameter (data); var msg = "The current state of the connection is not Open.";
throw new InvalidOperationException (msg);
if (msg != null) {
_logger.Error (msg);
error ("An error has occurred in sending data.", null);
return;
} }
send (Opcode.Text, new MemoryStream (data.UTF8Encode ())); if (data == null)
throw new ArgumentNullException ("data");
byte[] bytes;
if (!data.TryGetUTF8EncodedBytes (out bytes))
throw new ArgumentException ("Cannot be UTF8 encoded.", "data");
send (Opcode.Text, new MemoryStream (bytes));
} }
/// <summary> /// <summary>