fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <exception>
  4. using namespace std;
  5.  
  6. int randomint() {
  7. throw std::runtime_error("whoops");
  8.  
  9. return 4;
  10. }
  11.  
  12. struct Movable {
  13. Movable():value(1997){}
  14. Movable(Movable&& other){std::cout << "move ctor\n"; other.value=0;}
  15. int value;
  16. };
  17.  
  18. void byval(Movable x, int y) {
  19. std::cout << x.value + y << "\n";
  20. }
  21.  
  22. int main() {
  23.  
  24. Movable n;
  25. try {
  26. byval(std::move(n), randomint());
  27. } catch (std::exception& e) {
  28. std::cout << e.what() << "\n";
  29. }
  30.  
  31. std::cout << "intact: " << n.value << "\n";
  32. return 0;
  33. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
whoops
intact: 1997