fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4.  
  5. struct Exception
  6. {
  7. std::string what;
  8. Exception(const std::string & what_) : what(what_) {}
  9. };
  10.  
  11.  
  12. std::string f()
  13. {
  14. throw Exception("Hello, world!");
  15. }
  16.  
  17. void g()
  18. {
  19. try
  20. {
  21. f();
  22. }
  23. catch (...)
  24. {
  25. throw Exception(f());
  26. }
  27. }
  28.  
  29.  
  30. int main(int argc, char ** argv)
  31. {
  32. try
  33. {
  34. g();
  35. }
  36. catch (const Exception & e)
  37. {
  38. std::cerr << e.what << std::endl;
  39. }
  40.  
  41. /// returns 1 in gcc 4.6.3, 4.8.1 - bug
  42. std::cerr << std::uncaught_exception() << std::endl;
  43.  
  44. return 0;
  45. }
Success #stdin #stdout #stderr 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Hello, world!
1