diff --git a/src/lib/MBS.Web/WebServer.cs b/src/lib/MBS.Web/WebServer.cs index eb60042..4829259 100644 --- a/src/lib/MBS.Web/WebServer.cs +++ b/src/lib/MBS.Web/WebServer.cs @@ -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,27 +387,56 @@ public class WebServer { // Console.WriteLine("Client connected"); - try + if (Debugger.IsAttached) { - HandleClient(client); + // 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); + } + */ } - catch (System.Net.Sockets.SocketException ex) + else { - Console.Error.WriteLine("caught SocketException; ignoring"); - Console.Error.WriteLine(ex.Message); + // also catch generic exceptions if we are not debugging + 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); + } } - 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); - } - client.Close(); } }