What to return with Exception Handling?

Topics: Exception Handling Application Block
Apr 3, 2008 at 7:27 AM
Hi - I am looking at using the Exception Handling Application Block, and was wondering about the following.

Many methods (for example those in a data-access-layer) return an object or throw an exception if something went wrong. What should the method return if the ExceptionPolicy.HandleException method returns false? Should it return null, should it return an "empty" object? All the examples I have found on the net rethrow the exception if ExceptionPolicy.HandleException returns true, but they don't discuss what should happen if it returns false.

Suddenly the clients of the DAL method (which originally expected receiving an object containing real data, or an exception) need to cope with a null or empty object sometimes or an exception (depending on the configuration).

Also, many examples I have seen are formed like this:
bool rethrow = ExceptionPolicy.HandleException(....
if (rethrow) throw;

Why not just:
if (ExceptionPolicy.HandleException(....

Thanks, Peter
Apr 3, 2008 at 12:53 PM
If your DAC is designed to give back an Object or an Exception all the time, then it is your exception handling block, that needs to be configured to rethrow all the time, after handling the exception. Its a design thing.

The second part of your question, i guess its just a coding practice . I dont see any harm doing