Throwing an error when initializing an object in c++ Let's say that when initializing a pet class, I wanted to exclude or disallow dogs or cats as species. What would be the proper way to throw an invalid_argument exception?

using std::string;
#include &lt;stdexcept&gt;
using std:: invalid_argument;
struct Pet {
  const string name;
  long age = 0;
  const string species;
  Pet() : name("Dan"), age(0), species("alligator"){}
  Pet(const string &amp; the_name, const string &amp; the_species): name(the_name),
  species(the_species), age(0) {};
};
Pet(const string &amp; the_name, const string &amp; the_species): name(the_name), species(the_species), age(0)
  {

     if (species == "cats" || species == "dogs")
        throw std::invalid_argument( "received negative value" );
  }