Click here to Skip to main content
15,897,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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.
Posted
Comments
Sander Rossel 31-Jan-12 13:21pm    
What's your calling code? As far as I can see this should be fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900