The CppReference page for make_shared says (same with make_unique)
May throw std::bad_alloc or any exception thrown by the constructor of T. If an exception is thrown, the functions have no effect.
This means that std::bad_alloc exeception can be thrown in case of a failure. "the functions have no effect" implicitly means that it cannot return a nullptr. If this is the case, why is it not a common practice to write make_shared/make_unique always into a try catch block?
What is the proper way to use a make_shared? Within try catch block? or Checking for nullptr?
Aucun commentaire:
Enregistrer un commentaire