View Single Post
  #1 (permalink)  
Old 08-03-2007, 01:23 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,321
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Default Windows Communication Foundation

Hi guys,

I am writing WCF services which are utilizing COM+ application, now I am unable to decide on exception management i.e. whether to use error codes or exception for business errors. Let me give you an example:

public Document GetDocument(int docId)

Now there can be following outputs when you call this method

- throws exception if database is down

Can be easily handled via exception management

- Returns null if document not found

- Returns null if document is not in active state (Business case)

Now the above cases, they return the same output but the reasons are different and I want to show the reason to the client, what can be the best practice?

One of the options I were thinking of

public Document GetDocument(int docId, out enum returnErrorCode)

so enum can have values DocumentNotFound, DocumentNotInActiveState etc

First of all I don’t like this approach and secondly caller will have to do lot of if checks after the method call which is weird.

The other option i am thinking to have two type of base exceptions derived from WCF FaultException, one to handle all unknown/technical exceptions and one to handle pure business errors with ErrorCode in it. The only benefit we'll be getting with this approach that WCF clients will be handling just these exceptions instead of writing various if checks. But still not sure it’s correct to handle business errors via exceptions.

Please advice.
Regards
__________________
Prasanna Vignesh
MCPD | Web Developer
Reply With Quote
Sponsored Links