I am unable to handle and suppress errors in my service without clients knowing about them. Someone tell me what I am doing wrong.
Given a WCF service function as follows
public MyType GetMyType(bool blCry)
{
try
{
if(blCry) throw new Exception("ouch");
}
catch(Exception)
{
}
return new MyType();
}
This works without problem - on the client I am getting MyType - all good.
But if I replace throw new Exception("ouch"); line with something like
DataTable dtNew = null;
DataRow dtBad = dtNew.NewRow();
and get a real exception then despite the fact that it is caught and "handled" and according to debugger the function gets to the end and returns MyType as expected, the client gets an CommunicationException:
{"The underlying connection was closed: The connection was closed unexpectedly."}
This exception is lying too, because if I ask the client to execute the line of code where he calls this function again, it does so and my service gets this request - even though I have not re-opened the supposedly broken connection.
So it appears that the error handling in my service can only handle errors that I throw myself... which is not good at all.