请帮我看看这段C#代码一般应该Catch些什么Exception?

while (true)
{
TcpListener tcpListener = new TcpListener(Program.MessageListenerPort);

tcpListener.Start();

TcpClient tcpClient = tcpListener.AcceptTcpClient();
NetworkStream networkStream = tcpClient.GetStream();

.......

networkStream.Close();
tcpListener.Stop();
tcpClient.Close();
}

该在哪儿加些什么东西呢?
最新回答
几闲人

2024-10-02 07:59:46

try
{
TcpClient tcpClient = tcpListener.AcceptTcpClient();
NetworkStream networkStream = tcpClient.GetStream();

.......

}
catch 代码
{
异常抛在这里,比如与客户端建立连接失败。
}