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;
    }
}

相关文章:

  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
猜你喜欢
  • 2021-08-05
  • 2022-12-23
  • 2022-01-01
  • 2021-06-28
  • 2022-02-04
  • 2021-05-27
  • 2022-12-23
相关资源
相似解决方案