Should I use noexcept for getters always?

noexcept is a promise that is very hard to take back. For example, you could later do something as simple as change the return type to std::string (for whatever reason), but because that needs to allocate a copy of the string, it can throw.

So the standard went the way of “add noexcept only when it’s necessary or highly beneficial”, and I think that’s a good rule to follow. The question you need to ask yourself is, will the callers of this method need it to not throw?

Leave a Comment