First of all, I’d recommend using an existing IRC framework instead of writing your own. I’m using a modified version of Thresher IRC, which I optimized for Twitch’s IRC. That way you don’t have to deal with exceptions originating from IRC itself.
ReadLine() CAN return null though. Also, it doesn’t matter that you assign an empty string before calling ReadLine() because it gets overwritten.
The documentation says
Return Value
Type: System.String
The next line from the input stream, or null if the end of the input stream is reached.
you could do something like that
string line = null;
while ((line = _reader.ReadLine()) != null)
{
try
{
// Parse line
}
catch (Exception e)
{
// Do something here
}
}
And since this is your own IRC implementation, are you responding to PING properly?