I am writing a C++ class which has two different usage models. One is external, where we assume the user does not want any exceptions to be raised. Instead, error codes are returned.
The other way of usage is internal, where I strive to avoid tedious error code checking and prefer to handle exceptions.
What would be a good way to combine the two approaches?
Edit:
- Both approaches may be used in the same binary
- Explicit is better than implicit
- Avoid exposing special constructs to user.
Create two versions of the class, one which throws and one which returns error codes. They can both derive from a common base that contains the bulk of the code.