I'm writing a C++ class. Some of its fields are STL containers, some aren't. While writing the methods I began wondering, how should I handle invalid values passed to methods? For example, some methods are more or less wrappers to STL container methods. Many STL methods just have "undefined behavior" when invalid iterators are passed. I guess it's like that because it allows the STL code to ignore these cases and thus be faster.
But for higher level code, what should I do? I do throw exceptions when an unexpected error occurs, for example an error made by a mistake a developer made. But in this case the parameter value depends on the interface user, not on the implementor. I could ignore invalid parameters and invalid iterators, etc. and "pass" the problem to lower-level functions, which would then have undefined behavior, but I could also throw an exception or at least find some way to report an error.
What would be the best thing to do?
Example: I have a class representing a tree node and it has a method add_child() which takes a std::shared_ptr parameter. Should I check the value or let the user make sure a nullptr isn't passed? Or for an invalid iterator, pass it to STL methods or report an error? If I should report - are exceptions the right solution?