I have a C# Windows UI program, with a Window1 : Window in whose constructor I start an asynchronous socket server that while (true) { /* BeginAccept */ } and streams data to any client that connects using BeginSend and EndSend.
If one of the clients is forcibly disconnected Socket.EndSend throws an exception (a bit surprisingly ObjectDisposedException instead of SocketException, but whatever).
That exception terminates my whole program (closing the window) but does not print a stack trace!
Instead, I only get an innocent
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
message in the Ouput panel.
If exceptions are silenced like this but still crash my program without stack trace, how am I supposed to find where the exception is thrown?
Well, it depends on what version of .NET you are using. But, that’s generally what’s documented will happen.
If you don’t want that to happen, use top-level exception handlers in your thread entry points and “swallow” the exception–logging it or whatever else you want to do before exiting the thread.
In terms of methods like
BeginSend, the method given toBeginSend(orBeginAcceptfor that matter) is effectively the thread entry-point. e.g.