Are the messages thrown by standard library exceptions defined?

Viewed 55

std::vector::at throws a std::out_of_range if the requested value is not in range of the container.

The constructor for std::out_of_range requires a string, which can be accessed through .what() when catching the exception.

But I have never seen anything written about what must actually be in that message. This can be useful to know for at least two reasons:

  • I might want to display this message to a user, for example when running with debug options enabled. Then it is good to know if there are any limits on the length, language, character set, etc.
  • I might want to use std::out_of_range in my own class if it is similar enough to a standard container, and return a message that is in line with the format used in the standard library.

Is this defined in the standard? If not, is it defined to not be defined?

1 Answers

I searched through n4659 (early c++17 draft).

There is no reference to the string used to initialise these exceptions when thrown by the standard library at all.

I did not see a guarantee that the string would be printable, although I suspect that in all implementations they will be:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf

Related