Trouble with Try/Catch illegal argument exceptions

Hey guys,

I'm a bit confused about how to "throw" an illegal argument exception and do the whole try/catch thing.

In particular, I would like to do this to test the constructor and methods of a class I built.

So here is the situation - say I want the constructor to throw an illegal argument error if a parameter it receives is equal to or below 2, and execute smoothly otherwise.

#include <iostream>
#include <stdexcept>

Cat::Cat(int x)
{
if(x<=2)
{
throw what???
}
else
{
//execute code normally
}
}

int main()
{
bool pass = false;
Cat store;
try {
store = new Cat(2);
}
catch(invalid_argument& e)
{
cout<<"Invalid Argument: "<< e.what() << endl;
}
return 0;
}

How exactly do I "throw" an illegal argument from my constructor? My question extends to other exceptions as well, like runtime exceptions.
Topic archived. No new replies allowed.