I have a confusing problem and I could not any way to workaround it. I have a couple of lines of codes, and at some point, the Send
function throws a System.Net.Sockets.SocketException
. However, even though try has the catch block, it does not catches the exception and continue with normal flow. When I try to run the case where it needs to throw same exception, catch captures it pretty well.
Things I have tried:
- Trying to change VS debugging settings 'Enable Only For My Code', but it is already disabled.
- I tried to both Debug and Release modes.
- I tried using general Exception catcher, but none of them worked.
Here is the code, at some point, the connection from the server closes and the c
Socket disconnects. It returns the System.Net.Sockets.SocketException
, but below catch does not capture it.
try
{
// Some code here . . .
c.Send(clientData);
Print("Started uploading the file " + uploadFilename + ".");
upBox.Text = "";
Print("Finished uploading the file " + uploadFilename + ".");
}
catch (System.Net.Sockets.SocketException)
{
Print("You are disconnected from server!");
}