fork download
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. ~A() { std::cout << "A::~A" << std::endl; }
  6. };
  7.  
  8. struct B : public A
  9. {
  10. ~B() { std::cout << "B::~B" << std::endl; }
  11. };
  12.  
  13. void throwit()
  14. {
  15. throw B{};
  16. }
  17.  
  18. int main()
  19. {
  20. std::cout << "beginning main scope" << std::endl;
  21.  
  22. {
  23. std::cout << "beginning inner scope" << std::endl;
  24.  
  25. try
  26. {
  27. std::cout << "calling throwit()" << std::endl;
  28. throwit();
  29. }
  30. catch (A& a)
  31. {
  32. std::cout << "caught exception" << std::endl;
  33. }
  34.  
  35. std::cout << "ending inner scope" << std::endl;
  36. }
  37.  
  38. std::cout << "ending main scope" << std::endl;
  39. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
beginning main scope
beginning inner scope
calling throwit()
caught exception
B::~B
A::~A
ending inner scope
ending main scope