// Function that call to read function of tcpClient and catches all // The exceptions that can happen. private string ReadFromServer() { try { string strFromServer = client.Read(); readSucceed = true; return(strFromServer); } catch (ObjectDisposedException) { return(HandleOtherExceptions(ReadObjectDisposedException)); } catch (InvalidOperationException) { return(HandleOtherExceptions(ReadInvalidOperationException)); } catch (TimeoutException) { return(HandleOtherExceptions(ReadTimeoutException)); } catch (IOException e) { return(HandleIOException(e)); } catch (Exception) { return(HandleOtherExceptions(RegularException)); } }
// Function that call to read function of tcpClient and catches all // The exceptions that can happen. private string ReadFromServer() { try { string strFromServer = client.Read(); readSucceed = true; return(strFromServer); } catch (ObjectDisposedException) { readSucceed = false; return(ReadObjectDisposedException); } catch (InvalidOperationException) { readSucceed = false; return(ReadInvalidOperationException); } catch (TimeoutException) { readSucceed = false; return(ReadTimeoutException); } catch (IOException e) { readSucceed = false; string msg; // Sometimes there is timeout but this exception belongs to IOException. if (e.Message.Contains("Unable to read data from the transport " + "connection: A connection attempt failed because the connected" + " party did not properly respond after a period of time, or" + " established connection failed because connected host has " + "failed to respond.")) { msg = ReadTimeoutException; } else { // Regular IOException. msg = ReadIOException; } return(msg); } catch (Exception) { readSucceed = false; return(RegularException); } }