I work in C #, so I placed it under C #, although this may be a question that can be answered in any programming language.
Sometimes I create a method that will do something like registering a user on a website. Often I return a boolean from a method, but this often causes problems because the boolean return does not convey any context. If an error occurs during user registration, I do not know what caused the error.
Here is an example of a method that I am currently using, but would like to change it so that it returns more than just 0 or 1.
public bool LoginToTwitter(String username, String password) {
The above method can only return True or False. This works well because I can just call the following:
if(http.LoginToTwitter(username, password)) { // Logged in } else { // Not Logged in }
But the problem is that I cannot understand why the user was not registered. There may be a number of reasons: an incorrect combination of username and password, a suspended account, an account requires the attention of users, etc. But using the following method and logic, it is impossible to find out.
What alternative approaches do I have?
c #
James jeffery
source share