I have a web method like this as part of a web service
public List<CustomObject> GetInformation() {
List<CustomObject> cc = new List<CustomObject>();
// Execute a SQL command
dr = SQL.Execute(sql);
if (dr != null) {
while(dr.Read()) {
CustomObject c = new CustomObject()
c.Key = dr[0].ToString();
c.Value = dr[1].ToString();
c.Meta = dr[2].ToString();
cc.Add(c);
}
}
return cc;
}
I want to incorporate error handling into this so that if the no rows are returned or if dr is null or if something else goes wrong, I want to return the exception in the form of an error description. However, if the function is returning List<CustomObject> how can I also return an error message to the client when something goes wrong?
I will create a wrapper class which has both your
ListofCustomObjectand the error information as another Property.Now I will return an object of this class from my Method
EDIT: To make it more reusable and generic, It is a good idea to create a seperate class to handle this. and I will have this in my Baseclass as a property
And Let all your Child entities involved in a transaction inherit from this base class.
Now from your Method you may set the values of OperationStatus property as needed