Reputation: 697
I want to use the std::string(size_type count,CharT ch)
with a big value for count
. Reading https://en.cppreference.com/w/cpp/string/basic_string/basic_string, I could not find an exception definition for this constructor, in case it fails.
If it is correct, although there is not a noexcept
clause in the constructor, how can I be sure that the string was created? Should I check if its size is not 0?
Upvotes: 1
Views: 134
Reputation: 9835
Your link says it under Exceptions:
Throws std::length_error if the length of the constructed string would exceed max_size() (for example, if count > max_size() for (2)). Calls to Allocator::allocate may throw.
Also std::string
uses an allocator which means std::bad_alloc
can be thrown aswell, if the allocator fails to allocate the requested amount of memory.
Upvotes: 5