I recently came across code like this of a collegue:
public object SomeMethod
{
DataSet ds = DataService.RetrieveData();
if(ds.Tables[0].Rows.Count > 0)
{
...code...
return prod;
}
throw new Exception("error message");
}
As you can see, the exception is thrown when the dataset is empty.
What I find wrong with this code is the way the throw almost seems unconditional.
public object SomeMethod
{
DataSet ds = DataService.RetrieveData();
if(ds.Tables[0].Rows.Count > 0)
{
...code...
return prod;
}
else
{
throw new Exception("error message");
}
}
This two ways of handling this functionality both work, but what do you think/prefer?