c# - Return values from Function -
I have a function that requests the person, the person returns the id, however, if the method detects a mistake , Then I want to return an error (with details).
Then, say that my work is:
public int GetPersonId (string username) {// logic return person ID; } Within logic, I call a proc, and return an id. However, if no result was returned, I could return -1, and handle it in the calling code - but I think it is not good.
Would it be better to make an exception, this, or what? I am sure that I have read once, throwing an exception to the type of business rules is not a good practice.
What is the best way to deal with it.
In addition, the proc will probably return the other conditions, such as 'the person is present but marked as deleted', 'such a person is not present' etc. I mean there is more than one 'exception'.
I think that what you do and what's not in your function clearly distinguish it is required. If no result is found then it is an error (only you can define what it is or not), then make an exception if this is not an error (because there is a potential output), then a code back or whatever You also want the calling code to manage it. But do not use exception handling to deal with the arguments of any program. This is incorrect
Comments
Post a Comment