locked
What is the best way to handle exception RRS feed

  • Question

  • User-1643735512 posted

    Hi All,

    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. 

    Monday, August 17, 2009 11:48 AM

Answers

  • User1696475319 posted

    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.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 17, 2009 4:32 PM

All replies

  • User1696475319 posted

    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.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 17, 2009 4:32 PM
  • User-1643735512 posted

    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?

     

     

     

     

     

    Thursday, February 11, 2010 4:42 AM