Note that there are some explanatory texts on larger screens.

plurals
  1. POc# exception not caught
    primarykey
    data
    text
    <p>I have a method that is a listener for a TCP client which looks like this:</p> <pre><code> private static void ProcessClient( Object obj) { ISession session = (ISession)obj; NetworkStream networkStream = null; try { DebugUtility.SetThreadName("Worker: {0}", session.Name); networkStream = session.TcpClient.GetStream(); networkStream.ReadTimeout = Config.ReadTimeout; // Loop received packets (blocks untill next packet) Int32 packetSize; Byte[] buffer = new Byte[session.PacketSize]; while ((packetSize = networkStream.Read(buffer, 0, buffer.Length)) != 0) { // Get String from packet bytes String packet = Encoding.UTF8.GetString(buffer, 0, packetSize); // Check if packet has data if (String.IsNullOrEmpty(packet)) continue; // Log biggest received package DebugUtility.CheckMaxPacketSize(session.Name, packet.Length); // Handle packet (in new thread) Logger.DebugLog("Received: {0}", packet); ThreadPool.QueueUserWorkItem(session.HandlePacket, packet); } } catch (ObjectDisposedException) { } catch (NotSupportedException) { } catch (TimeoutException) { } catch (SocketException) { } catch (IOException) { } catch (Exception ex) { Logger.LogException(ex); } finally { if (networkStream != null) networkStream.Close(); if (session != null) session.Disconnect(); } } </code></pre> <p>This is for a game service but when I check my logs, I occasionally see this error:</p> <pre><code>System.Int32 Read(Byte[], Int32, Int32): The stream does not support reading. at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at BusinessLayer.Listener.ListenerWorker.ProcessClient(Object obj) in C:\path\ListenerWorker.cs:line 141 Line: 0 </code></pre> <p>That is the above described file and line 141 is </p> <pre><code> while ((packetSize = networkStream.Read(buffer,.... </code></pre> <p>Now I have found that NotSupportedException is throwing this error, but why does it go through? Why is it not ignored but does it fall through the normal Exception ex handler?</p> <p>Edit: Does anyone know how I can invoke this exception? When does it occur? I only see it coming back in my logs to other users, but I don't know when it happens.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload