tags:

views:

504

answers:

5

Should a web service return an exception or an empty result when data is not found?

+6  A: 

If no data is a normal and acceptable result (as it normally is), it should return an empty result set. You should only return an exception if an error/exception has occurred.

gkrogers
A: 

How about an error message that describes the problem?

Patrick Cuff
In many cases, 0 results is not an error.
ceejayoz
A: 

That depends entirely on the domain of the problem. If there should never be a time that no result is found them that is an error. If no results is an acceptible condition then an empty result set is fine. It just depends on the specific problem. As someone consuming the webservice that is what I would expect. An error is a problem.

Ryan Guill
+1  A: 

A regular .net exception is a platform specific construct that should not be returned outside the webservice since the client calling upon the service might not implement such a thing, instead use a SoapException for exceptional circumstances

Is the empty result set something the client calling the webservice can recover from? If so I wouldn’t return the SoapException. If it’s something that’s so exceptional that it warrants a special handling logic then by all means do use the SoapException.

There resources might help you along

olle
A: 

Thank you all for your response. Your responses are all common sense and right where I was thinking. However, our application architect had other ideas. Now, the returned exception will be changed from a sql exception to a more informative one. We have agreed that an empty result is acceptable only where the parameter doesn't exist in a relationship table but an exception will result if the value isn't in the value table at all.

Thank you all for being the subject matter experts today!