fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. struct Foo {
  5. int x_;
  6. Foo (int const x): x_(x) {
  7. if (x == 1) {
  8. throw x;
  9. }
  10. }
  11. ~Foo() { std::cerr << "foo_" << x_ << " destroyed" << std::endl; }
  12. };
  13.  
  14. struct Bar {
  15. std::shared_ptr<Foo> foo_0;
  16. std::shared_ptr<Foo> foo_1;
  17. std::shared_ptr<Foo> foo_2;
  18. Bar():
  19. foo_0 (std::make_shared<Foo>(0)),
  20. foo_1 (std::make_shared<Foo>(1)),
  21. foo_2 (std::make_shared<Foo>(2)) {
  22. }
  23. ~Bar() {
  24. std::cerr << "Bar destroyed" << std::endl;
  25. }
  26. };
  27.  
  28. void xul() {
  29. Bar bar;
  30. }
  31.  
  32. int main() {
  33. try { xul(); } catch (...) { return EXIT_FAILURE; }
  34. }
Runtime error #stdin #stdout #stderr 0s 3428KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
foo_0 destroyed