catch exceptions differently if we are debugging

This commit is contained in:
Michael Becker 2025-03-06 16:17:52 -05:00
parent 38bf02d406
commit 04dabc6455

View File

@ -1,4 +1,5 @@
using System.Net;
using System.Diagnostics;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
@ -386,6 +387,35 @@ public class WebServer
{
// Console.WriteLine("Client connected");
if (Debugger.IsAttached)
{
// do not catch generic exceptions when running under a debugger
try
{
HandleClient(client);
}
catch (System.Net.Sockets.SocketException ex)
{
Console.Error.WriteLine("caught SocketException; ignoring");
Console.Error.WriteLine(ex.Message);
}
catch (System.IO.IOException ex)
{
Console.Error.WriteLine("caught IOException; ignoring");
Console.Error.WriteLine(ex.Message);
}
/*
catch (Exception ex)
{
Console.Error.WriteLine("caught exception of type {0}", ex.GetType().FullName);
Console.Error.WriteLine(ex.Message);
Console.Error.WriteLine(ex.StackTrace);
}
*/
}
else
{
// also catch generic exceptions if we are not debugging
try
{
HandleClient(client);
@ -406,7 +436,7 @@ public class WebServer
Console.Error.WriteLine(ex.Message);
Console.Error.WriteLine(ex.StackTrace);
}
}
client.Close();
}
}