When we declare a std::vector, or std::string, ..., like that for example
std::string hello("Hello");
isn't it wrong? shouldn't we do
std::string hello;
try {
hello = "Hello";
} catch (std::exception &e) {
std::cout << e.what() << std::endl;
return (-1);
}
Because if I understood how it works, when an allocation fails, it will result in an uncaught exception otherwise, so why do I often see code like this ? :
std::string s("hello");
s += " world";
s += "!";
s.reserve(100);
...
without any check?