That's right, if something you call from a specific member function (including constructors, implicit calls that the compiler provides for you, etc.) can throw an exception, then the member function can throw an exception. So this is no exception for free.
What to do about it: it really depends on what your code should do, and "what you can do if it throws an exception." You probably want to catch it SOMEWHERE, but since the scenario is most likely that you did something stupid and / or ran out of memory, you probably won’t be able to do much in this situation. (Of course, if you use, for example, std::vector::at() value out of range, then it will throw an exception - that "do something stupid" - similar to what I did a couple of times, const char* p = 0; .... std:string str(p); - this may, of course, fail, and not an exception, but my compiler seems to throw a bad_something exception from this). Any of these things, if they are not intended, are probably "the death of your code anyway." If you use std::vector::at() with a poor index, and you "intended it", then you will probably think about your design - exceptions are "expensive" compared to if (vec.size() > index) ... else ...
I'm not sure if there is a specific term for "my class does not throw exceptions, but uses a standard library that can do it."
source share