fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A {
  5. A() { cout << "A()" << endl; }
  6. A(const A &a) { cout << "A(const A&)" << endl; }
  7. virtual ~A() { cout << "~A()" << endl; }
  8. };
  9.  
  10. struct B : public A {
  11. B() { cout << "B()" << endl; }
  12. ~B() { cout << "~B()" << endl; }
  13. };
  14.  
  15. int main() {
  16. try {
  17. throw B();
  18. } catch (A a) {
  19. cout << "Catched" << endl;
  20. }
  21. cout << "After catch" << endl;
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 2816KB
stdin
Standard input is empty
stdout
A()
B()
A(const A&)
Catched
~A()
~B()
~A()
After catch