fork(3) download
  1. #include <iostream>
  2. #include <exception>
  3.  
  4. using namespace std;
  5.  
  6. struct base
  7. {
  8. base()
  9. {
  10. throw std::exception();
  11. }
  12. };
  13.  
  14. struct derived : public base
  15. {
  16. derived() try : base()
  17. {
  18. throw std::exception();
  19. }
  20. catch (std::exception& e) // will catch exceptions thrown base constructor
  21. {
  22. std::cout << "catch" << std::endl;
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. derived a;
  29. // your code goes here
  30. return 0;
  31. }
Runtime error #stdin #stdout #stderr 0s 3460KB
stdin
Standard input is empty
stdout
catch1
stderr
terminate called after throwing an instance of 'std::exception'
  what():  std::exception