fork download
  1. #include <iostream>
  2. #include <exception>
  3.  
  4. struct ex
  5. {
  6. ex()
  7. {
  8. throw std::runtime_error("Some error");
  9. }
  10. };
  11.  
  12. struct dummy
  13. {
  14. dummy()
  15. try : e(ex())
  16. {
  17. std::cout << "dummy ctor" << std::endl;
  18. }
  19. catch (std::runtime_error const& e)
  20. {
  21. std::cout << e.what() << std::endl;
  22. }
  23.  
  24. private:
  25. ex e;
  26. };
  27.  
  28. int main()
  29. {
  30. dummy d;
  31.  
  32. return 0;
  33. }
Runtime error #stdin #stdout #stderr 0s 15232KB
stdin
Standard input is empty
stdout
Some error
stderr
terminate called after throwing an instance of 'std::runtime_error'
  what():  Some error