I am developing a library for future use in other libraries or end products. Let's say the user uses the library incorrectly, passing an invalid value to a public function, calling the functions in the wrong order, etc.
In this case, I could throw an exception, but they are usually intended for the final products and should be handled accordingly, while here we have a mistake from developers who did not read the documentation properly. On the other hand, he or she is a user of my library and, therefore, a statement may be the wrong way (imagine a statement, burned in code that you never wrote and was expected to only work).
So far, I have used statements only inside private internal functions and methods, thereby only reporting my errors inside the library. In case of improper use of the library by users, I always throw an exception with a description of the error (and advice on how to avoid it).
Do you think this is the right approach? If not, what rule of thumb do you use for statements and exceptions when designing a library?
source share