Handling Derived-Class Exceptions : Exception « Exceptions « C++ Tutorial






#include <iostream>
using namespace std;
   
class B {
};
   
class D: public B {
};
   
int main()
{
  D derived;
   
  try {
    throw derived;
  }
  catch(B b) {
    cout << "Caught a base class.\n";
  }
  catch(D d) {
    cout << "This won't execute.\n";
  }
   
  return 0;
}








6.3.Exception
6.3.1.Declaring exception specifications in class hierarchy
6.3.2.Handling Derived-Class Exceptions
6.3.3.Demonstrating stack unwinding