fork download
  1. #include <iostream>
  2.  
  3. struct FirstWillThrow {
  4. static bool first_time;
  5.  
  6. FirstWillThrow() {
  7. if (first_time) {
  8. std::cout << "FirstWillThrow the first time" << std::endl;
  9. first_time = false;
  10. throw 0;
  11. }
  12. std::cout << "FirstWillThrow all other times" << std::endl;
  13. }
  14. };
  15.  
  16. bool FirstWillThrow::first_time = true;
  17.  
  18. void foo(bool flag) {
  19. std::cout << "foo" << std::endl;
  20.  
  21. if(flag) {
  22. static FirstWillThrow fwt;
  23. }
  24. }
  25.  
  26. int main(void) {
  27. foo(false);
  28.  
  29. try {
  30. foo(true);
  31. } catch(...) {
  32.  
  33. }
  34.  
  35. foo(true);
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
foo
foo
FirstWillThrow the first time
foo
FirstWillThrow all other times