I want to throw my own exceptions with the base class Exception. There is a virtual method print which will be overwritten by the subclasses. I onl
You can use a pointer instead of reference to avoid slicing:
int main(int argc, char **argv)
{
try
{
IllegalArgumentException* pIAE = new IllegalArgumentException();
throw pIAE;
}
catch(IllegalArgumentException* i)
{
i->print();
}
}
The caught pointer points to the same object, because the copy constructor is not called implicitly.