Last post Feb 11, 2010 04:42 AM by webfriend13
Aug 17, 2009 11:48 AM|webfriend13|LINK
Ours is an NTier WCF based web application. We are throwing exception in almost all the layers including the lowest layer(the Data access layers). When the exception comes at the client, we are handling the exception.
But each time we throw exception, I have seen the memory consumption shoots up. This made me think, What is the best way to handle exception?
Since this is a WCF application, is it a good idea to throw exception from your services? If not what is the alternative?
Thanks in advance.
Aug 17, 2009 04:32 PM|mendhak|LINK
It all depends on the requirements and what you want clients to know about.
Yes, exceptions are costly, so your observations are right.
If the client doesn't really need to know what's wrong with the service, then handle the exception in the service and return 'nulls' or nothing and ensure that the client can handle empty values gracefully without kicking up a fuss. You can, in turn, log
the exception somewhere so that if the behavior is persistent, you check the error logs to see what's wrong with the service.
If you want to display the exceptions to the user, then the client does need to know what's wrong with the service and so you should allow the exception to go all the way.
Feb 11, 2010 04:42 AM|webfriend13|LINK
Thank you for the reply & you made a valid point that if client wants to see, what went wrong, we need to throw the exception from our WCF service.
What If, I still want my client to see the error details & avoid throwing the exceptions from WCF service. What approcah you will suggest me?