Some functions should be non-throwing, but the standard doesn't say anything about it. Such as erase(q)
(q
denotes a valid dereferenceable constant iterator) of associative containers. This allows the implementation to throw any standard exception, according to [res.on.exception.handling#4]:
Functions defined in the C++ standard library that do not have a Throws: paragraph but do have a potentially-throwing exception specification may throw implementation-defined exceptions.170 Implementations should report errors by throwing exceptions of or derived from the standard exception classes ([bad.alloc], [support.exception], [std.exceptions]).
So if you want to swallow any implementation-defined exceptions they throw, you have to use a try-catch block.
std::set<int> s{1};
try
{
s.erase(s.cbegin());
}
catch (...) {}
It's ugly and inefficient, but necessary. So I also don't know of any benefit to this.