We will start from an example to illustrate the c++ exception. Two classes is in the example: Person and Student. class Student is the child class of class Person.
class Person
{
};
class Student : public Person
{
};
void func()
{
Student student;
try
{
throw student; // copy student object as exception object
}
catch (Student& s) // use the exception object as a reference
{
std::cout << "catch Student& s" << std::endl;
}
catch (...)
{
std::cout << "catch Exception e" << std::endl;
}
}