# Throwing an error when initializing an object in c++ [closed]

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 <stdexcept>
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 & the_name, const string & the_species): name(the_name),
species(the_species), age(0) {};
};


## closed as off-topic by David Richerby, Yuval Filmus, Evil, chi, Raphael♦Jun 13 '17 at 4:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Questions about software development or programming tools are off-topic here, but can be asked on Stack Overflow." – David Richerby, Yuval Filmus, Evil, chi
If this question can be reworded to fit the rules in the help center, please edit the question.

• Your question is a programming question, and I think you should ask it on StackOverflow. – Christopher Bell II Jun 12 '17 at 21:52

Pet(const string & the_name, const string & the_species): name(the_name), species(the_species), age(0)