Hi,
I’m writing a set of classes and am trying to find the best way in general to handle errors which may be encountered within these classes.
For instance, i have a class which handles most things to do with a user. One of the class’s methods is editUser which, when called by client code, first evaluates which of the user’s details have been changed. If the email has been changed another method within the same class is called to check that the email does not already exist.
Now, if the email address already exists then i want a suitable error message to be returned to the client code. If no details have been changed then i want another message returned to the client code. If the method completes successfully then i want it to return TRUE (or similar) to the client code. And if it fails for any other reason then i want to return FALSE (or similar).
What is the best regarded solution to doing things like this? One thing i thought of doing was returning codes from each part of the method like:
101 = email exists
102 = no changes made
103 = operation successful
104 = operation failed
..and then the client code can use a switch statement on the object and perform the relevant action.
What works best?