I have a function that requests a person, returning the person ID. However, if method detects a fault, I want to return an error (With a description?).
So, lets say my function is:
public int GetPersonId(string username)
{
//Logic
return personId;
}
Within the logic, I call a proc, and return an ID. However, if no results were returned, I could return -1, and handle that in the calling code - but feel this isn't good.
Would it be better the create an exception, and try/catch it, or what? I'm sure I read once, that throwing exceptions for business type rules, isn't good practise.
What's the best way to deal with this.
Additionally, maybe the proc will return other statuses, such as 'person exists, but is marked as deleted', 'no such person exists' etc. What I mean is there is more than one 'exception'.