How can std::runtime_error::runtime_error(const std::string&) meet std::exception's requirement of throw()?

Viewed 4200

std::exception requires that its constructor be throw(). Yet std::runtime_error accepts a std::string as its argument, which indicates that it's storing a std::string somewhere. Therefore, an assignment or copy construction has to be going on somewhere. And for std::string, that's not a nothrow operation.

How then does runtime_error::runtime_error meet throw()?

(For context, I'm implementing an exception type, and want to store a few std::strings from the call site, and I want to do it correctly...)

2 Answers
Related